// allocate more spaces to the given ByteBuffer private java.nio.ByteBuffer allocateMore(java.nio.ByteBuffer output) { if (output.capacity() == 0) { return(java.nio.ByteBuffer.allocate(1)); } java.nio.ByteBuffer result = java.nio.ByteBuffer.allocate(output.capacity() * 2); output.flip(); result.put(output); return(result); }
private LongToByteBufferAdapter(java.nio.ByteBuffer byteBuffer) : base(byteBuffer .capacity() / libcore.io.SizeOf.LONG) { this.byteBuffer = byteBuffer; this.byteBuffer.clear(); this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress; }
internal FloatToByteBufferAdapter(java.nio.ByteBuffer byteBuffer) : base(byteBuffer .capacity() / libcore.io.SizeOf.FLOAT) { this.byteBuffer = byteBuffer; this.byteBuffer.clear(); this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress; }
public static String getString(java.nio.ByteBuffer buffer, int offset, int len) { String s = ""; if (null != buffer && buffer.capacity() >= offset + len) { byte[] dest = new byte[len]; buffer.position(offset); buffer.get(dest, 0, len); s = new String(dest).trim(); } return(s); }
public override int read(char[] buffer, int offset, int length) { lock (@lock) { if (!isOpen()) { throw new System.IO.IOException("InputStreamReader is closed"); } java.util.Arrays.checkOffsetAndCount(buffer.Length, offset, length); if (length == 0) { return(0); } java.nio.CharBuffer @out = java.nio.CharBuffer.wrap(buffer, offset, length); java.nio.charset.CoderResult result = java.nio.charset.CoderResult.UNDERFLOW; // bytes.remaining() indicates number of bytes in buffer // when 1-st time entered, it'll be equal to zero bool needInput = !bytes.hasRemaining(); while (@out.hasRemaining()) { // fill the buffer if needed if (needInput) { try { if (@in.available() == 0 && @out.position() > offset) { // we could return the result without blocking read break; } } catch (System.IO.IOException) { } // available didn't work so just try the read int desiredByteCount = bytes.capacity() - bytes.limit(); int off = bytes.arrayOffset() + bytes.limit(); int actualByteCount = @in.read(((byte[])bytes.array()), off, desiredByteCount); if (actualByteCount == -1) { endOfInput = true; break; } else { if (actualByteCount == 0) { break; } } bytes.limit(bytes.limit() + actualByteCount); needInput = false; } // decode bytes result = decoder.decode(bytes, @out, false); if (result.isUnderflow()) { // compact the buffer if no space left if (bytes.limit() == bytes.capacity()) { bytes.compact(); bytes.limit(bytes.position()); bytes.position(0); } needInput = true; } else { break; } } if (result == java.nio.charset.CoderResult.UNDERFLOW && endOfInput) { result = decoder.decode(bytes, @out, true); decoder.flush(@out); decoder.reset(); } if (result.isMalformed() || result.isUnmappable()) { result.throwException(); } return(@out.position() - offset == 0 ? -1 : @out.position() - offset); } }