JAVA IO Buffer

Source: Internet
Author: User

The so-called input, output, is to remove or move the data into the buffer.

The hardware does not have direct access to the user control (JVM). A storage-based hardware device manipulates a fixed-size block of data, and the user requests an arbitrary-sized or unaligned chunk of data. Virtual Memory: Replace the physical address with a virtual address instead.
    1. You can have multiple virtual addresses pointing to the same physical address.
    2. The virtual memory space can be larger than the actual hardware memory.
Application: Direct Memory usage--using the virtual address of the user and the virtual address of the kernel to point to the same physical address, you can make the hardware directly access the space memory.

Applications such as databases rely heavily on file locking.

Buffer:

A buffer is an array of basic data types that are wrapped within an object. Buffer contains data about the content and information contained in an object, and defines a series of APIs. Information provides operation properties: 0<=mark<=position<=limit<=capicity
    1. Capacity (capicity): Set at creation time and cannot be changed dynamically.
    2. Upper bound (Limit): The count of existing elements.
    3. Position (Position): The location of the next element to be read. Dynamic updates.
    4. Mark: Memo location, Mark () set Mark=position,reset () set Postion=mark.
After inserting "Hello":

Buffer class method signature: Some methods that return buffer itself can be called directly. Create a read-only cache. For example Bytebuffer: bytebuffer bf = Bytebuffer.allocate (1024x768). Asreadonlybuffer ()Flip (): A buffer that can continue to add the fill state of the data element is flipped to a ready-to-read element's release state. bf.flip () = Bf.limit (Bf.position ()). Position (0)

Rewind (): bf.rewind () = bf.position (0)  The buffer is not thread safe. Mark (): Buffer is the output from the current position to the channel within the content, such as, how to output ' ow ', position to 6

Reset (), positon to mark position. Two buffer with the same element, as long as the number of remaining elements (from the position to the upper bound) is the same, equals=true. Buffer.get (byte[]): bufferunderflowexception; When a buffer content is read into an array, the buffer content is not sufficient to populate the array, this exception is thrown. Because you need to indicate the length of the buffer content that can be read in. as follows: Buffer.get (byte[], 0, buffer.remaining ()); Buffer.put (byte[]): Bufferunderflowexception, this exception is thrown when an array element is written to buffer,buffer there is not enough space.

JAVA IO Buffer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.