/// <exception cref="System.IO.IOException"/> public static void fillBuffer(java.nio.ByteBuffer buffer, java.nio.channels.ReadableByteChannel bc) { while (buffer.hasRemaining()) { int r = bc.Read(buffer); if (r < 0) { throw new System.IO.IOException("premature EOF"); } } }
/// <exception cref="System.IO.IOException"/> public static Capnproto.MessageReader Read(java.nio.channels.ReadableByteChannel bc, Capnproto.ReaderOptions options) { java.nio.ByteBuffer firstWord = makeByteBuffer(Capnproto.Constants.BYTES_PER_WORD); fillBuffer(firstWord, bc); int segmentCount = 1 + firstWord.getInt(0); int segment0Size = 0; if (segmentCount > 0) { segment0Size = firstWord.getInt(4); } int totalWords = segment0Size; if (segmentCount > 512) { throw new System.IO.IOException("too many segments"); } //In words. System.Collections.Generic.List <int> moreSizes = new System.Collections.Generic.List <int>(); if (segmentCount > 1) { java.nio.ByteBuffer moreSizesRaw = makeByteBuffer(4 * (segmentCount & ~1)); fillBuffer(moreSizesRaw, bc); for (int ii = 0; ii < segmentCount - 1; ++ii) { int size = moreSizesRaw.getInt(ii * 4); moreSizes.Add(size); totalWords += size; } } if (totalWords > options.traversalLimitInWords) { throw new Capnproto.DecodeException("Message size exceeds traversal limit."); } java.nio.ByteBuffer allSegments = makeByteBuffer(totalWords * Capnproto.Constants.BYTES_PER_WORD); fillBuffer(allSegments, bc); java.nio.ByteBuffer[] segmentSlices = new java.nio.ByteBuffer[segmentCount]; allSegments.rewind(); segmentSlices[0] = allSegments.slice(); segmentSlices[0].limit(segment0Size * Capnproto.Constants.BYTES_PER_WORD); segmentSlices[0].order(java.nio.ByteOrder.LITTLE_ENDIAN); int offset = segment0Size; for (int ii = 1; ii < segmentCount; ++ii) { allSegments.position(offset * Capnproto.Constants.BYTES_PER_WORD); segmentSlices[ii] = allSegments.slice(); segmentSlices[ii].limit(moreSizes[ii - 1] * Capnproto.Constants.BYTES_PER_WORD); segmentSlices[ii].order(java.nio.ByteOrder.LITTLE_ENDIAN); offset += moreSizes[ii - 1]; } return(new Capnproto.MessageReader(segmentSlices, options)); }
public override long transferFrom(java.nio.channels.ReadableByteChannel arg0, long arg1, long arg2) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; if (!IsClrObject) { return(@__env.CallLongMethod(this.JvmHandle, global::java.nio.channels.FileChannel_._transferFrom14454, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2))); } else { return(@__env.CallNonVirtualLongMethod(this.JvmHandle, global::java.nio.channels.FileChannel_.staticClass, global::java.nio.channels.FileChannel_._transferFrom14454, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2))); } }
/// <exception cref="System.IO.IOException"/> public static int readAtLeast(java.nio.channels.ReadableByteChannel reader, java.nio.ByteBuffer buf, int minBytes) { int numRead = 0; while (numRead < minBytes) { int res = reader.Read(buf); if (res < 0) { throw new System.Exception("premature EOF"); } numRead += res; } return(numRead); }
//TODO: Check for r == 0? /// <exception cref="System.IO.IOException"/> public static Capnproto.MessageReader Read(java.nio.channels.ReadableByteChannel bc) { return(Read(bc, Capnproto.ReaderOptions.DEFAULT_READER_OPTIONS)); }
public BufferedInputStreamWrapper(java.nio.channels.ReadableByteChannel chan) { this.inner = chan; this.buf = java.nio.ByteBuffer.allocate(8192); this.buf.limit(0); }
public abstract long transferFrom(java.nio.channels.ReadableByteChannel arg0, long arg1, long arg2);
/// <exception cref="System.IO.IOException"/> public static Capnproto.MessageReader ReadFromUnbuffered(java.nio.channels.ReadableByteChannel input, Capnproto.ReaderOptions options) { Capnproto.PackedInputStream packedInput = new Capnproto.PackedInputStream(new Capnproto.BufferedInputStreamWrapper(input)); return(Capnproto.Serialize.Read(packedInput, options)); }
/// <exception cref="System.IO.IOException"/> public static Capnproto.MessageReader ReadFromUnbuffered(java.nio.channels.ReadableByteChannel input) { return(ReadFromUnbuffered(input, Capnproto.ReaderOptions.DEFAULT_READER_OPTIONS)); }