Java 8 MappedByteBuffer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 MappedByteBuffer class.

This code example shows how to use the following methods:putLong, force
 
    public void shutdown() { 
        this.flush();
 
        // unmap mappedByteBuffer 
        MapedFile.clean(this.mappedByteBuffer);
 
        try { 
            this.fileChannel.close();
        } 
        catch (IOException e) {
            e.printStackTrace();
        } 
    } 
 
 
    public void flush() { 
        this.mappedByteBuffer.putLong(0, this.physicMsgTimestamp);
        this.mappedByteBuffer.putLong(8, this.logicsMsgTimestamp);
        this.mappedByteBuffer.putLong(16, this.indexMsgTimestamp);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:putLong, force
 
    public void shutdown() { 
        this.flush();
 
        // unmap mappedByteBuffer 
        MapedFile.clean(this.mappedByteBuffer);
 
        try { 
            this.fileChannel.close();
        } 
        catch (IOException e) {
            e.printStackTrace();
        } 
    } 
 
 
    public void flush() { 
        this.mappedByteBuffer.putLong(0, this.physicMsgTimestamp);
        this.mappedByteBuffer.putLong(8, this.logicsMsgTimestamp);
        this.mappedByteBuffer.putLong(16, this.indexMsgTimestamp);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:position, get
            throws IOException { 
        // ÒѾ­É¾³ý£¬²»ÓüÌÐø¶Á 
        if (this.deleted) {
            return; 
        } 
        mappedByteBuffer.position(offset);
        if (!loadItem) {
            final byte data = mappedByteBuffer.get();
            this.deleted = (data == (byte) 1 ? true : false);
        } 
        else { 
            final byte[] bytes = new byte[SIZE];
            mappedByteBuffer.get(bytes, 0, SIZE);
            this.deleted = (bytes[0] == (byte) 1 ? true : false);
            this.opItem = new OpItem();
            this.opItem.parse(bytes, 1, bytes.length - 1);
        } 
    } 
 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:position, putLong, force
    { 
        try 
        { 
            if ( mappedBuffer != null )
            { 
                mappedStartPosition += mappedBuffer.position();
                mappedBuffer.force();
                mappedBuffer = null;
            } 
            if ( mapFail > 1000 )
            { 
                mapFail = -1;
            } 
            if ( mapFail > 0 )
            { 
                mapFail++;
                return; 
            } 
            mappedBuffer = fileChannel.map( MapMode.READ_WRITE,
                mappedStartPosition, MAPPED_SIZE );

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:position, remaining, duplicate
     * @return buffer with portion of file content 
     * @throws IOException on any fail of I/O operation 
     */ 
    public synchronized ByteBuffer readBytes(int length) throws IOException
    { 
        int remaining = buffer.remaining() - position;
        if (length > remaining)
            throw new IOException(String.format("mmap segment underflow; remaining is %d but %d requested",
                                                remaining, length));
 
        ByteBuffer bytes = buffer.duplicate();
        bytes.position(buffer.position() + position).limit(buffer.position() + position + length);
        position += length;
 
        return bytes;
    } 
 
    @Override 
    public final void readFully(byte[] buffer) throws IOException
    { 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:limit, position, remaining, isLoaded, load
		map.reset();
	} 
 
	@Override 
	public long skip(long n) throws IOException {
		if (!map.isLoaded()) {
			map.load();
		} 
		if (map.position() + n > map.limit()) {
			long ret = map.remaining();
			map.position(map.limit());
			return ret;
		} else { 
			map.position((int) (map.position() + n));
			return n;
		} 
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:flip, position, get, getInt, putInt
This code example shows how to use the following methods:rewind, putInt, putLong, force
		m_index = 0;
	} 
 
	private void saveMark() { 
		try { 
			m_byteBuffer.rewind();
			m_byteBuffer.putInt(m_index);
			m_byteBuffer.putLong(m_timestamp);
 
			if (m_index % 100 == 0) {
				m_byteBuffer.force();
			} 
		} catch (Exception e) {
			// ignore it 
		} 
	} 
 
	public void setDomain(String domain) {
		m_domain = domain;
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:remaining, get
 
    public byte[] read(int len) throws EoflvException {
        // System.err.println("reading position: " + pos + " len=" + len); 
        byte[] buf = new byte[len];
 
        if (len > data.remaining()) {
            written = data.remaining();
            data.get(buf, 0, written);
            fillBuffer(); 
            data.get(buf, written, (len - written));
            // data.position((len-written)); 
        } else { 
            data.get(buf);
        } 
 
        pos += len;
 
        return buf;
 
    }// read() 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:putDouble
        final int chunkSize = 100 * MiB;
 
        MappedFile mappedFile = MappedFile.open(file, chunkSize);
        try { 
            final MappedByteBuffer buffer1 = mappedFile.getBuffer();
            buffer1.putDouble(0, 0.111);
            buffer1.putDouble(chunkSize - 8, 1.222);
        } finally { 
            assertEquals(chunkSize, file.length());
        } 
 
        try { 
            final MappedByteBuffer buffer2 = mappedFile.remap(0, 2 * chunkSize);
            assertEquals(0.111, buffer2.getDouble(0), 1e-10);
            assertEquals(1.222, buffer2.getDouble(chunkSize - 8), 1e-10);
            buffer2.putDouble(2 * chunkSize - 8, 2.333);
        } finally { 
            assertEquals(2 * chunkSize, file.length());
        } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 MappedByteBuffer Questions & Answers:

See Code Examples for Java 8 MappedByteBuffer Methods: