I 流
java operations on the data stream by way of, for processing the data stream IO transfer between devices, file uploading and downloading files, Java objects for the operation of the flow in the IO package.
Base class byte stream | Inputstream | OutputStream |
Byte stream file operation | FileInputStream | FileOutputStream |
Byte buffer flow (high flow) | BufferedInputStream | BufferedOutputStream |
NIO
Three major components: chanel, buffer, selector
###FileChannel和buffer的简单使用 RandomAccessFile accessFile = null; try { accessFile = new RandomAccessFile("test.txt", "rw"); FileChannel channel = accessFile.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024); int bytesRead; while ((bytesRead = channel.read(buffer)) != -1) { buffer.flip(); while (buffer.hasRemaining()) { System.out.print((char) buffer.get()); } buffer.compact(); } } finally { accessFile.close(); }
Use Buffer (buffer) of
buffer: Buffer, actually a container, continuous array. Channel provides read data from files, network channels, but reading and writing of data must pass through buffer.
The buffer can be simply understood as a set of elements of the list of basic data types, it is to save the state of the current position data by several variables: capacity, position, limit, mark.
index | Explanation |
---|---|
capacity | The total length of the array of buffers |
position | The position of the next data element to be operated |
limit | Position of the next element in the buffer array inoperable: limit <= capacity |
mark | For recording the position of the current position of a front or a default -1 |
effect | Related Methods |
---|---|
Allocated space | ByteBuffer buffer = ByteBuffer.allocate(1024); |
Data is written into buffer | int bytesRead = channel.read(buffer) |
Analyzing the data in buffer | boolean b=buffer.hasRemaining() |
Reading data from the Buffer | buffer.get() |
starting time | buffer.flip() |
When it ends | buffer.compact() |
Methods of Using Arrays
-
The array into List:
List<String> list = Arrays.asList(arr.split(","));
-
According to sort an array of ASCII code:
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
Iterator of use
【---list---】 List<Integer> list = new ArrayList<>(); //遍历 while (iterator.hasNext()) { System.out.print(iterator.next() + " "); } //删除 while (iterator.hasNext()) { iterator.remove(); } 【---map---】 Map<Integer, String> map = new HashMap<>(); Iterator<Integer> it = map.keySet().iterator(); while(it.hasNext()) { Integer key = it.next(); System.out.println(key+"->"+map.get(key)); }
JVM-related
Memory Allocation
command | Explanation |
---|---|
Xms | When referring to the size of memory for the program set to start |
Xmx | Is the maximum that can be consumed during the setup process is running on memory size |
Xss | It refers to the set of each thread stack size |
These three parameters are set to default Byte units may be added to [k / K] or [m / M] in the later figures to KB or MB.