コード例 #1
0
 private static void PutColor(java.nio.ByteBuffer buffer, ref Color color)
 {
     buffer.put((sbyte)color.R);
     buffer.put((sbyte)color.G);
     buffer.put((sbyte)color.B);
     buffer.put((sbyte)color.A);
 }
コード例 #2
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual Chunk readChunk()
        {
            java.nio.ByteBuffer chunkHeadBuffer = this.readBytes(ArangoDBConstants
                                                                 .CHUNK_MIN_HEADER_SIZE);
            int  length    = chunkHeadBuffer.getInt();
            int  chunkX    = chunkHeadBuffer.getInt();
            long messageId = chunkHeadBuffer.getLong();
            long messageLength;
            int  contentLength;

            if ((1 == (chunkX & unchecked ((int)0x1))) && (chunkX >> 1 > 1))
            {
                messageLength = this.readBytes(ArangoDBConstants.LONG_BYTES).getLong
                                    ();
                contentLength = length - ArangoDBConstants.CHUNK_MAX_HEADER_SIZE;
            }
            else
            {
                messageLength = -1L;
                contentLength = length - ArangoDBConstants.CHUNK_MIN_HEADER_SIZE;
            }
            Chunk chunk = new Chunk
                              (messageId, chunkX, messageLength, 0, contentLength);

            if (LOGGER.isDebugEnabled())
            {
                LOGGER.debug(string.format("Received chunk %s:%s from message %s", chunk.getChunk
                                               (), chunk.isFirstChunk() ? 1 : 0, chunk.getMessageId()));
            }
            return(chunk);
        }
コード例 #3
0
 internal static java.nio.ByteBuffer makeByteBuffer(int bytes)
 {
     java.nio.ByteBuffer result = java.nio.ByteBuffer.prepare(bytes);
     result.order(java.nio.ByteOrder.LITTLE_ENDIAN);
     result.mark();
     return(result);
 }
コード例 #4
0
 internal FloatToByteBufferAdapter(java.nio.ByteBuffer byteBuffer) : base(byteBuffer
                                                                          .capacity() / libcore.io.SizeOf.FLOAT)
 {
     this.byteBuffer = byteBuffer;
     this.byteBuffer.clear();
     this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
 }
コード例 #5
0
		internal FloatToByteBufferAdapter(java.nio.ByteBuffer byteBuffer) : base(byteBuffer
			.capacity() / libcore.io.SizeOf.FLOAT)
		{
			this.byteBuffer = byteBuffer;
			this.byteBuffer.clear();
			this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
		}
コード例 #6
0
 private LongToByteBufferAdapter(java.nio.ByteBuffer byteBuffer) : base(byteBuffer
                                                                        .capacity() / libcore.io.SizeOf.LONG)
 {
     this.byteBuffer = byteBuffer;
     this.byteBuffer.clear();
     this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
 }
コード例 #7
0
 public static int dgeev(char jobvl, char jobvr, int n, java.nio.ByteBuffer A, int
                         offA, int ldA, java.nio.ByteBuffer WR, java.nio.ByteBuffer WI, java.nio.ByteBuffer
                         VL, int offVL, int ldVL, java.nio.ByteBuffer VR, int offVR, int ldVR, java.nio.ByteBuffer
                         work, int lwork)
 {
     throw new System.NotSupportedException("TODO");
 }
コード例 #8
0
            private static void FromVertexPositionColorTexture4(
                SpriteBatch.VertexPositionColorTexture4[] array,
                int offset, int length, java.nio.ByteBuffer buffer)
            {
                ValidateOffsetAndLength(offset, length, 96);

                int index = offset / 96;
                int count = length / 96;

                for (; count-- > 0; index++)
                {
                    PutVector3(buffer, ref array[index].Position0);
                    PutColor(buffer, ref array[index].Color0);
                    PutVector2(buffer, ref array[index].TextureCoordinate0);

                    PutVector3(buffer, ref array[index].Position1);
                    PutColor(buffer, ref array[index].Color1);
                    PutVector2(buffer, ref array[index].TextureCoordinate1);

                    PutVector3(buffer, ref array[index].Position2);
                    PutColor(buffer, ref array[index].Color2);
                    PutVector2(buffer, ref array[index].TextureCoordinate2);

                    PutVector3(buffer, ref array[index].Position3);
                    PutColor(buffer, ref array[index].Color3);
                    PutVector2(buffer, ref array[index].TextureCoordinate3);
                }
            }
コード例 #9
0
        /*
         * Defines a Class using the class bytes obtained from the specified
         * Resource. The resulting Class must be resolved before it can be
         * used.
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private Class defineClass(String name, sun.misc.Resource res) throws java.io.IOException
        private Class DefineClass(String name, Resource res)
        {
            long t0  = System.nanoTime();
            int  i   = name.LastIndexOf('.');
            URL  url = res.CodeSourceURL;

            if (i != -1)
            {
                String pkgname = name.Substring(0, i);
                // Check if package already loaded.
                Manifest man = res.Manifest;
                DefinePackageInternal(pkgname, man, url);
            }
            // Now read the class bytes and define the class
            java.nio.ByteBuffer bb = res.ByteBuffer;
            if (bb != null)
            {
                // Use (direct) ByteBuffer:
                CodeSigner[] signers = res.CodeSigners;
                CodeSource   cs      = new CodeSource(url, signers);
                sun.misc.PerfCounter.ReadClassBytesTime.addElapsedTimeFrom(t0);
                return(DefineClass(name, bb, cs));
            }
            else
            {
                sbyte[] b = res.Bytes;
                // must read certificates AFTER reading bytes.
                CodeSigner[] signers = res.CodeSigners;
                CodeSource   cs      = new CodeSource(url, signers);
                sun.misc.PerfCounter.ReadClassBytesTime.addElapsedTimeFrom(t0);
                return(DefineClass(name, b, 0, b.Length, cs));
            }
        }
コード例 #10
0
 internal static java.nio.ShortBuffer asShortBuffer(java.nio.ByteBuffer byteBuffer
                                                    )
 {
     java.nio.ByteBuffer slice_1 = byteBuffer.slice();
     slice_1.order(byteBuffer.order());
     return(new java.nio.ShortToByteBufferAdapter(slice_1));
 }
コード例 #11
0
        private void parseFrameFileIndexAndPathnameTables(java.nio.ByteBuffer buffer)
        {
            int theSectionOffset = buffer.position();
            Hashtable <Integer, String> pathnames = new Hashtable <Integer, String>();

            for (int i = 0; i < this.numOfFrameFileIndexRecords; i++)
            {
                this.frameFileIndexTable.add(new RPFFrameFileIndexRecord(buffer));
            }

            for (int i = 0; i < this.numOfPathnameRecords; i++)
            {
                int relOffset = buffer.position() - theSectionOffset;
                int len       = NITFSUtil.getUShort(buffer);
                pathnames.put(relOffset, NITFSUtil.getString(buffer, len));
            }

            if (0 < this.frameFileIndexTable.size() && 0 < pathnames.size())
            { // update pathname field in every RPFFrameFileIndexRecord
                foreach (RPFFrameFileIndexRecord rec in this.frameFileIndexTable)
                {
                    int offset = (int)rec.getPathnameRecordOffset();
                    if (pathnames.containsKey(offset))
                    {
                        rec.setPathname(pathnames.get(offset));
                    }
                    else
                    {
                        throw new NITFSRuntimeException("NITFSReader.CorrespondingPathnameWasNotFound");
                    }
                }
            }
        }
コード例 #12
0
		private IntToByteBufferAdapter(java.nio.ByteBuffer byteBuffer) : base(byteBuffer.
			capacity() / libcore.io.SizeOf.INT)
		{
			this.byteBuffer = byteBuffer;
			this.byteBuffer.clear();
			this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
		}
コード例 #13
0
        ///Upon return, `bb.position()` will be at the end of the message.
        /// <exception cref="System.IO.IOException"/>
        public static Capnproto.MessageReader Read(java.nio.ByteBuffer bb, Capnproto.ReaderOptions options)
        {
            bb.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            int segmentCount = 1 + bb.getInt();

            if (segmentCount > 512)
            {
                throw new System.IO.IOException("too many segments");
            }
            java.nio.ByteBuffer[] segmentSlices = new java.nio.ByteBuffer[segmentCount];
            int segmentSizesBase = bb.position();
            int segmentSizesSize = segmentCount * 4;
            int align            = Capnproto.Constants.BYTES_PER_WORD - 1;
            int segmentBase      = (segmentSizesBase + segmentSizesSize + align) & ~align;
            int totalWords       = 0;

            for (int ii = 0; ii < segmentCount; ++ii)
            {
                int segmentSize = bb.getInt(segmentSizesBase + ii * 4);
                bb.position(segmentBase + totalWords * Capnproto.Constants.BYTES_PER_WORD);
                segmentSlices[ii] = bb.slice();
                segmentSlices[ii].limit(segmentSize * Capnproto.Constants.BYTES_PER_WORD);
                segmentSlices[ii].order(java.nio.ByteOrder.LITTLE_ENDIAN);
                totalWords += segmentSize;
            }
            bb.position(segmentBase + totalWords * Capnproto.Constants.BYTES_PER_WORD);
            if (totalWords > options.traversalLimitInWords)
            {
                throw new Capnproto.DecodeException("Message size exceeds traversal limit.");
            }
            return(new Capnproto.MessageReader(segmentSlices, options));
        }
コード例 #14
0
 public DoubleColMatrix(java.nio.ByteBuffer buffer, int baseOffset, int numRows, int
                        numCols)
     : base(buffer, numRows, numCols)
 {
     columnCapacity  = numCols;
     this.baseOffset = baseOffset;
 }
コード例 #15
0
        /// <exception cref="System.IO.IOException"/>
        public static void Write(java.nio.channels.WritableByteChannel outputChannel, Capnproto.MessageBuilder message)
        {
            java.nio.ByteBuffer[] segments = message.GetSegmentsForOutput();
            int tableSize = (segments.Length + 2) & (~1);

            java.nio.ByteBuffer table = java.nio.ByteBuffer.allocate(4 * tableSize);
            table.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            table.putInt(0, segments.Length - 1);
            for (int i = 0; i < segments.Length; ++i)
            {
                table.putInt(4 * (i + 1), segments[i].limit() / 8);
            }
            //Any padding is already zeroed.
            while (table.hasRemaining())
            {
                outputChannel.Write(table);
            }
            foreach (java.nio.ByteBuffer buffer in segments)
            {
                while (buffer.hasRemaining())
                {
                    outputChannel.Write(buffer);
                }
            }
        }
コード例 #16
0
ファイル: TestCase.cs プロジェクト: ntbova/capnproto-dotnet
 /// <exception cref="System.IO.IOException"/>
 public virtual void passByBytes(RequestFactory requestFactory, ResponseFactory responseFactory, Compression compression, long iters)
 {
     java.nio.ByteBuffer requestBytes  = java.nio.ByteBuffer.allocate(SCRATCH_SIZE * 8);
     java.nio.ByteBuffer responseBytes = java.nio.ByteBuffer.allocate(SCRATCH_SIZE * 8);
     Common.FastRand     rng           = new Common.FastRand();
     for (int i = 0; i < iters; ++i)
     {
         MessageBuilder  requestMessage  = new MessageBuilder();
         MessageBuilder  responseMessage = new MessageBuilder();
         RequestBuilder  request         = requestMessage.InitRoot(requestFactory);
         Expectation     expected        = this.setupRequest(rng, request);
         ResponseBuilder response        = responseMessage.InitRoot(responseFactory);
         {
             ArrayOutputStream writer = new ArrayOutputStream(requestBytes);
             compression.writeBuffered(writer, requestMessage);
         }
         {
             MessageReader messageReader = compression.newBufferedReader(new ArrayInputStream(requestBytes));
             this.handleRequest(messageReader.GetRoot(requestFactory), response);
         }
         {
             ArrayOutputStream writer = new ArrayOutputStream(responseBytes);
             compression.writeBuffered(writer, responseMessage);
         }
         {
             MessageReader messageReader = compression.newBufferedReader(new ArrayInputStream(responseBytes));
             if (!this.checkResponse(messageReader.GetRoot(responseFactory), expected))
             {
                 throw new System.Exception("incorrect response");
             }
         }
     }
 }
コード例 #17
0
        public RPFFrameFileComponents(java.nio.ByteBuffer buffer)
        {
            this.componentLocationTable = new RPFLocationSection(buffer);

            if (0 < this.componentLocationTable.getCoverageSectionSubheaderLength())
            {
                this.parseRPFCoverageSection(buffer);
            }

            if (0 < this.componentLocationTable.getColorGrayscaleSectionSubheaderLength())
            {
                this.parseColorGrayscaleSection(buffer);
            }

            if (0 < this.componentLocationTable.getColormapSubsectionLength())
            {
                this.parseColormapSubSection(buffer);
            }

            if (0 < this.componentLocationTable.getColorConverterSubsectionLength())
            {
                this.parseColorConverterSubsection(buffer);
            }

            if (0 < this.componentLocationTable.getImageDescriptionSubheaderLength())
            {
                buffer.position(this.componentLocationTable.getImageDescriptionSubheaderLocation());
                this.parseImageDescriptionSubheader(buffer);
            }
            if (0 < this.componentLocationTable.getRelatedImagesSectionSubheaderLength())
            {
                buffer.position(this.componentLocationTable.getRelatedImagesSectionSubheaderLocation());
                this.relatedImagesSection = new RelatedImagesSection(buffer);
            }
        }
コード例 #18
0
        public void compressImage(java.awt.image.BufferedImage image, DXTCompressionAttributes attributes,
                                  java.nio.ByteBuffer buffer)
        {
            if (image == null)
            {
                String message = Logging.getMessage("nullValue.ImageIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (attributes == null)
            {
                String message = Logging.getMessage("nullValue.AttributesIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.BufferNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            // If it is determined that the image and block have no alpha component, then we compress with DXT1 using a
            // four color palette. Otherwise, we use the three color palette (with the fourth color as transparent black).

            ColorBlock4x4       colorBlock          = new ColorBlock4x4();
            ColorBlockExtractor colorBlockExtractor = this.getColorBlockExtractor(image);

            BlockDXT1           dxt1Block      = new BlockDXT1();
            BlockDXT1Compressor dxt1Compressor = new BlockDXT1Compressor();

            int width  = image.getWidth();
            int height = image.getHeight();

            bool imageHasAlpha  = image.getColorModel().hasAlpha();
            bool enableAlpha    = attributes.isEnableDXT1Alpha();
            int  alphaThreshold = attributes.getDXT1AlphaThreshold();

            for (int j = 0; j < height; j += 4)
            {
                for (int i = 0; i < width; i += 4)
                {
                    colorBlockExtractor.extractColorBlock4x4(attributes, i, j, colorBlock);

                    if (enableAlpha && imageHasAlpha && blockHasDXT1Alpha(colorBlock, alphaThreshold))
                    {
                        dxt1Compressor.compressBlockDXT1a(colorBlock, attributes, dxt1Block);
                    }
                    else
                    {
                        dxt1Compressor.compressBlockDXT1(colorBlock, attributes, dxt1Block);
                    }

                    buffer.putShort((short)dxt1Block.color0);
                    buffer.putShort((short)dxt1Block.color1);
                    buffer.putInt((int)dxt1Block.colorIndexMask);
                }
            }
        }
コード例 #19
0
        public ByteBufferRaster(int width, int height, Sector sector, java.nio.ByteBuffer byteBuffer, AVList list)
        {
            base(width, height, sector, BufferWrapper.wrap(byteBuffer, list), list);

            this.byteBuffer = byteBuffer;

            this.validateParameters(list);
        }
コード例 #20
0
        private NITFSMessage(java.nio.ByteBuffer buffer)
        {
            this.buffer     = buffer;
            this.fileHeader = new NITFSFileHeader(buffer);

            // read ALL description groups and segments
            this.readSegments();
        }
コード例 #21
0
        private void parseColorGrayscaleSection(java.nio.ByteBuffer buffer)
        {
            buffer.position(this.componentLocationTable.getColorGrayscaleSectionSubheaderLocation());

            this.numOfColorGrayscaleOffsetRecords = NITFSUtil.getByteAsShort(buffer);
            this.numOfColorConverterOffsetRecords = NITFSUtil.getByteAsShort(buffer);
            this.externalColorGrayscaleFilename   = NITFSUtil.getString(buffer, 12);
        }
コード例 #22
0
        public RPFFileComponents(java.nio.ByteBuffer buffer)
        {
            this.buffer        = buffer;
            this.headerSection = new RPFHeaderSection(buffer);

            buffer.position(this.headerSection.locationSectionLocation);
            this.locationSection = new RPFLocationSection(buffer);
        }
コード例 #23
0
ファイル: Data.cs プロジェクト: losttech/capnproto-dotnet
 public Reader()
 {
     // in bytes
     // in bytes
     this.buffer = java.nio.ByteBuffer.allocate(0);
     this.offset = 0;
     this.size   = 0;
 }
コード例 #24
0
ファイル: Data.cs プロジェクト: losttech/capnproto-dotnet
 public java.nio.ByteBuffer AsByteBuffer()
 {
     java.nio.ByteBuffer dup = this.buffer.asReadOnlyBuffer();
     dup.position(this.offset);
     java.nio.ByteBuffer result = dup.slice();
     result.limit(this.size);
     return(result);
 }
コード例 #25
0
ファイル: Data.cs プロジェクト: losttech/capnproto-dotnet
 public byte[] ToArray()
 {
     java.nio.ByteBuffer dup = this.buffer.duplicate();
     byte[] result           = new byte[this.size];
     dup.position(this.offset);
     dup.get(result, 0, this.size);
     return(result);
 }
コード例 #26
0
 private void parseRPFColorOffsetRecord(java.nio.ByteBuffer buffer)
 {
     this.tableID               = NITFSUtil.getUShort(buffer);
     this.numOfColorRecords     = NITFSUtil.getUInt(buffer);
     this.colorElementLength    = NITFSUtil.getByteAsShort(buffer);
     this.histogramRecordLength = NITFSUtil.getUShort(buffer);
     this.colorTableOffset      = NITFSUtil.getUInt(buffer);
     this.histogramTableOffset  = NITFSUtil.getUInt(buffer);
 }
コード例 #27
0
        public NITFSUserDefinedHeaderSegment(java.nio.ByteBuffer buffer)
        {
            base(NITFSSegmentType.USER_DEFINED_HEADER_SEGMENT, buffer, 0, 0, 0, 0);

            this.headerLength = Integer.parseInt(NITFSUtil.getString(buffer, 5));
            this.overflow     = Integer.parseInt(NITFSUtil.getString(buffer, 3));
            this.dataTag      = NITFSUtil.getString(buffer, 6);
            this.dataLength   = Integer.parseInt(NITFSUtil.getString(buffer, 5));
        }
コード例 #28
0
ファイル: Text.cs プロジェクト: losttech/capnproto-dotnet
 public Reader()
 {
     //in bytes
     //in bytes, not including NUL terminator
     //TODO: What about the null terminator?
     this.buffer = java.nio.ByteBuffer.allocate(0);
     this.offset = 0;
     this.size   = 0;
 }
コード例 #29
0
 public override java.nio.LongBuffer duplicate()
 {
     java.nio.ByteBuffer bb = byteBuffer.duplicate().order(byteBuffer.order());
     java.nio.LongToByteBufferAdapter buf = new java.nio.LongToByteBufferAdapter(bb);
     buf._limit    = _limit;
     buf._position = _position;
     buf._mark     = _mark;
     return(buf);
 }
コード例 #30
0
 public override java.nio.LongBuffer slice()
 {
     byteBuffer.limit(_limit * libcore.io.SizeOf.LONG);
     byteBuffer.position(_position * libcore.io.SizeOf.LONG);
     java.nio.ByteBuffer bb     = byteBuffer.slice().order(byteBuffer.order());
     java.nio.LongBuffer result = new java.nio.LongToByteBufferAdapter(bb);
     byteBuffer.clear();
     return(result);
 }
コード例 #31
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static long write(object nd, FileDescriptor fd, ByteBuffer[] bufs, int offset, int length)
        {
#if FIRST_PASS
            return(0);
#else
            ByteBuffer[] altBufs             = null;
            List <ArraySegment <byte> > list = new List <ArraySegment <byte> >(length);
            for (int i = 0; i < length; i++)
            {
                ByteBuffer bb = bufs[i + offset];
                if (!bb.hasArray())
                {
                    if (altBufs == null)
                    {
                        altBufs = new ByteBuffer[bufs.Length];
                    }
                    ByteBuffer abb = ByteBuffer.allocate(bb.remaining());
                    int        pos = bb.position();
                    abb.put(bb);
                    bb.position(pos);
                    abb.flip();
                    bb = altBufs[i + offset] = abb;
                }
                list.Add(new ArraySegment <byte>(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining()));
            }
            int count;
            try
            {
                count = fd.getSocket().Send(list);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                if (x.ErrorCode == global::java.net.SocketUtil.WSAEWOULDBLOCK)
                {
                    count = 0;
                }
                else
                {
                    throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
                }
            }
            catch (ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
            int total = count;
            for (int i = 0; total > 0 && i < length; i++)
            {
                ByteBuffer bb       = bufs[i + offset];
                int        consumed = Math.Min(total, bb.remaining());
                bb.position(bb.position() + consumed);
                total -= consumed;
            }
            return(count);
#endif
        }
コード例 #32
0
ファイル: BufferUtils.cs プロジェクト: Vestaxis/fastmath
 /// <summary>
 /// Copies a string to ByteBuffer, if byteBuffer overflows then not all of string
 /// is copied
 /// </summary>
 /// <param name="string"/>
 /// <param name="byteBuffer">destination buffer is duplicated first so that position is not list
 ///     </param>
 /// <returns>new byteBuffer</returns>
 public static java.nio.ByteBuffer copy(string @string, java.nio.ByteBuffer byteBuffer
                                        )
 {
     java.nio.ByteBuffer dupe = byteBuffer.duplicate();
     for (int i = 0; i < @string.Length && dupe.hasRemaining(); i++)
     {
         dupe.put(unchecked ((byte)@string[i]));
     }
     return(dupe);
 }
コード例 #33
0
		public override void close()
		{
			lock (@lock)
			{
				if (encoder != null)
				{
					drainEncoder();
					flushBytes(false);
					@out.close();
					encoder = null;
					bytes = null;
				}
			}
		}