List of usage examples for java.nio ByteBuffer remaining
public final int remaining()
From source file:org.apache.http.contrib.logging.Wire.java
public void input(final ByteBuffer b) { if (b.hasArray()) { input(b.array(), b.arrayOffset() + b.position(), b.remaining()); } else {//from w w w. j a v a 2s .c o m byte[] tmp = new byte[b.remaining()]; b.get(tmp); input(tmp); } }
From source file:fr.letroll.ttorrentandroid.client.storage.FileStorage.java
@Override public int write(ByteBuffer buffer, long offset) throws IOException { int length = buffer.remaining(); if (offset + length > this.size) throw new IllegalArgumentException("Invalid storage write request: offset=" + offset + ", length=" + length + " when size=" + this.size); return this.channel.write(buffer, offset); }
From source file:org.apache.http.contrib.logging.Wire.java
public void output(final ByteBuffer b) { if (b.hasArray()) { output(b.array(), b.arrayOffset() + b.position(), b.remaining()); } else {/* ww w .j a v a 2 s.c o m*/ byte[] tmp = new byte[b.remaining()]; b.get(tmp); output(tmp); } }
From source file:org.apache.http.HC4.impl.nio.conn.Wire.java
public void input(final ByteBuffer b) { if (b.hasArray()) { input(b.array(), b.arrayOffset() + b.position(), b.remaining()); } else {//from w ww .j a v a 2 s . c o m final byte[] tmp = new byte[b.remaining()]; b.get(tmp); input(tmp); } }
From source file:org.apache.http.HC4.impl.nio.conn.Wire.java
public void output(final ByteBuffer b) { if (b.hasArray()) { output(b.array(), b.arrayOffset() + b.position(), b.remaining()); } else {/*from www.jav a 2 s . c o m*/ final byte[] tmp = new byte[b.remaining()]; b.get(tmp); output(tmp); } }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
/**Calculate attribute value size*/ private static int calculateAttributeSizeInBytes(AttributeValue value) { int attrValSize = 0; if (value == null) { return attrValSize; }/*from w w w .j a va 2 s.c o m*/ if (value.getB() != null) { ByteBuffer b = value.getB(); attrValSize += b.remaining(); } else if (value.getS() != null) { String s = value.getS(); attrValSize += s.getBytes(UTF8).length; } else if (value.getN() != null) { attrValSize += MAX_NUMBER_OF_BYTES_FOR_NUMBER; } else if (value.getBS() != null) { List<ByteBuffer> bs = value.getBS(); for (ByteBuffer b : bs) { if (b != null) { attrValSize += b.remaining(); } } } else if (value.getSS() != null) { List<String> ss = value.getSS(); for (String s : ss) { if (s != null) { attrValSize += s.getBytes(UTF8).length; } } } else if (value.getNS() != null) { List<String> ns = value.getNS(); for (String n : ns) { if (n != null) { attrValSize += MAX_NUMBER_OF_BYTES_FOR_NUMBER; } } } else if (value.getBOOL() != null) { attrValSize += 1; } else if (value.getNULL() != null) { attrValSize += 1; } else if (value.getM() != null) { for (Map.Entry<String, AttributeValue> entry : value.getM().entrySet()) { attrValSize += entry.getKey().getBytes(UTF8).length; attrValSize += calculateAttributeSizeInBytes(entry.getValue()); attrValSize += BASE_LOGICAL_SIZE_OF_NESTED_TYPES; } attrValSize += LOGICAL_SIZE_OF_EMPTY_DOCUMENT; } else if (value.getL() != null) { List<AttributeValue> list = value.getL(); for (Integer i = 0; i < list.size(); i++) { attrValSize += calculateAttributeSizeInBytes(list.get(i)); attrValSize += BASE_LOGICAL_SIZE_OF_NESTED_TYPES; } attrValSize += LOGICAL_SIZE_OF_EMPTY_DOCUMENT; } return attrValSize; }
From source file:fr.letroll.ttorrentandroid.client.storage.FileStorage.java
@Override public int read(ByteBuffer buffer, long offset) throws IOException { int length = buffer.remaining(); if (offset + length > this.size) throw new IllegalArgumentException("Invalid storage read request: offset=" + offset + ", length=" + length + " when size=" + this.size); int read = this.channel.read(buffer, offset); if (read < length) throw new IOException("Storage underrun: offset=" + offset + ", length=" + length + ", size=" + size + ", read=" + read); return read;//from ww w . j ava 2 s . co m }
From source file:org.apache.cassandra.db.marshal.TimeUUIDType.java
public void validate(ByteBuffer bytes) throws MarshalException { if (bytes.remaining() != 16 && bytes.remaining() != 0) throw new MarshalException(String.format("TimeUUID should be 16 or 0 bytes (%d)", bytes.remaining())); ByteBuffer slice = bytes.slice(); // version is bits 4-7 of byte 6. if (bytes.remaining() > 0) { slice.position(6);//from w ww . j a v a 2 s . c o m if ((slice.get() & 0xf0) != 0x10) throw new MarshalException("Invalid version for TimeUUID type."); } }
From source file:edu.tamu.tcat.crypto.bouncycastle.SecureTokenImpl.java
private byte[] createToken(ByteBuffer content) throws NoSuchAlgorithmException { byte[] bytes = new byte[content.remaining()]; ByteBuffer tokenBytes = ByteBuffer.wrap(bytes); content.position(0);// www .j a va 2 s . c om tokenBytes.put(content); return bytes; }
From source file:com.bittorrent.mpetazzoni.client.storage.FileStorage.java
@Override public int write(ByteBuffer buffer, long offset) throws IOException { int requested = buffer.remaining(); if (offset + requested > this.size) { throw new IllegalArgumentException("Invalid storage write request!"); }//from w w w . j a v a 2 s . c o m return this.channel.write(buffer, offset); }