Examples of ByteBufferInputStream


Examples of de.netseeker.ejoe.io.ByteBufferInputStream

     * @throws IOException
     * @throws UnsupportedOperationException
     */
    private Object read( SerializeAdapter adapter ) throws IOException
    {
        ByteBufferInputStream in = null;
        ByteBuffer dataBuf = null;
        Object result = null;
        DataChannel dataChannel = DataChannel.getInstance( this._senderInfo );

        try
        {
            if ( !this._senderInfo.hasWaitingBuffer() )
            {
                int length = dataChannel.readHeader( this._senderInfo, EJConstants.EJOE_CONNECTION_TIMEOUT );

                // maybe the DataChannel signals that it has already read
                // partial data
                if ( this._senderInfo.hasWaitingBuffer() )
                {
                    dataBuf = this._senderInfo.getWaitingBuffer();
                }
                else
                {
                    dataBuf = ByteBufferAllocator.allocate( length );
                }

                log.log( Level.FINE, "Going to read client request with length: " + length );
            }
            else
            {
                dataBuf = this._senderInfo.getWaitingBuffer();
            }

            if ( dataBuf.hasRemaining() )
            {
                DataChannel.nonBlockingRead( this._senderInfo.getChannel(), dataBuf );
            }

            dataBuf.flip();

            if ( log.isLoggable( Level.FINE ) )
            {
                byte[] tmp = new byte[dataBuf.remaining()];
                dataBuf.get( tmp );
                dataBuf.position( 0 );
                log.log( Level.FINE, "Client request read:\n" + new String( tmp, EJConstants.EJOE_DEFAULT_CHARSET ) );
            }

            if ( dataBuf.hasRemaining() )
            {
                try
                {
                    // usual way: deserialize using a adapter
                    if ( !this._senderInfo.isDirect() )
                    {
                        dataBuf = dataChannel.decode( dataBuf );
                        in = new ByteBufferInputStream( dataBuf );
                        result = deserialize( adapter, in );
                    }
                    // direct mode: don't deserialize, just copy and return the read
                    // ByteBuffer
                    else
View Full Code Here

Examples of de.netseeker.ejoe.io.ByteBufferInputStream

    private Object receive( ConnectionHeader clientInfo ) throws IOException
    {
        Object result = null;
        DataChannel dataChannel = DataChannel.getInstance( _serverInfo );
        ByteBuffer dataBuf = clientInfo.getWaitingBuffer();
        ByteBufferInputStream in = null;

        try
        {
            if ( dataBuf == null )
            {
                int length = dataChannel.readHeader( _serverInfo, this._connectionTimeout );
                // server signals a null result?
                if ( length == 0 )
                {
                    return null;
                }

                // maybe the DataChannel signals that it has already read
                // partial data
                if ( _serverInfo.hasWaitingBuffer() )
                {
                    dataBuf = _serverInfo.getWaitingBuffer();
                }
                else
                {
                    dataBuf = ByteBufferAllocator.allocate( length );
                }

                log.log( Level.FINE, "Going to read server response with length: " + length );
            }

            if ( dataBuf.hasRemaining() )
            {
                DataChannel.nonBlockingRead( _channel, dataBuf );
            }

            dataBuf.flip();

            log
                    .log( Level.FINE,
                          "Response read. Now calling (de)serialize adapter to convert response back to object." );

            if ( dataBuf.hasRemaining() )
            {
                try
                {
                    // usual way: deserialize using a adapter
                    if ( !clientInfo.isDirect() && !clientInfo.isMixed() )
                    {
                        in = new ByteBufferInputStream( dataBuf );
                        result = deserialize( in, clientInfo );
                    }
                    // direct or mixed mode: don't deserialize, just copy and return
                    // the read ByteBuffer
                    else
View Full Code Here

Examples of edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream

import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;

public class ResultUtils {
    public static String getStringFromBuffer(ByteBuffer buffer, IFrameTupleAccessor fta) throws HyracksDataException {
        String resultRecords = "";
        ByteBufferInputStream bbis = new ByteBufferInputStream();
        try {
            fta.reset(buffer);
            for (int tIndex = 0; tIndex < fta.getTupleCount(); tIndex++) {
                int start = fta.getTupleStartOffset(tIndex);
                int length = fta.getTupleEndOffset(tIndex) - start;
                bbis.setByteBuffer(buffer, start);
                byte[] recordBytes = new byte[length];
                bbis.read(recordBytes, 0, length);
                resultRecords += new String(recordBytes, 0, length);
            }
        } finally {
            try {
                bbis.close();
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }
        return resultRecords;
View Full Code Here

Examples of freenet.support.ByteBufferInputStream

  short priority;
  private boolean needsLoadRT;
  private boolean needsLoadBulk;
 
  public static Message decodeMessageFromPacket(byte[] buf, int offset, int length, PeerContext peer, int overhead) {
    ByteBufferInputStream bb = new ByteBufferInputStream(buf, offset, length);
    return decodeMessage(bb, peer, length + overhead, true, false, false);
  }
View Full Code Here

Examples of freenet.support.ByteBufferInputStream

    ByteBufferInputStream bb = new ByteBufferInputStream(buf, offset, length);
    return decodeMessage(bb, peer, length + overhead, true, false, false);
  }
 
  public static Message decodeMessageLax(byte[] buf, PeerContext peer, int overhead) {
    ByteBufferInputStream bb = new ByteBufferInputStream(buf);
    return decodeMessage(bb, peer, buf.length + overhead, true, false, true);
  }
View Full Code Here

Examples of freenet.support.ByteBufferInputStream

          m.set(name, Serializer.readFromDataInputStream(type, bb));
        }
      }
      if (mayHaveSubMessages) {
        while (bb.remaining() > 2) { // sizeof(unsigned short) == 2
          ByteBufferInputStream bb2;
          try {
            int size = bb.readUnsignedShort();
            if (bb.remaining() < size) return m;
            bb2 = bb.slice(size);
          } catch (EOFException e) {
View Full Code Here

Examples of info.ata4.io.buffer.ByteBufferInputStream

        if (pbv.numItems == 0 || pbv.bitSize == 0) {
            return new int[]{};
        }
       
        // the values are packed with a variable bit length
        BitInputStream bis = new BitInputStream(new ByteBufferInputStream(pbv.data));
        bis.setBitLength(pbv.bitSize);
       
        int numItems = pbv.numItems.intValue();
        int[] items = new int[numItems];
        for (int i = 0; i < items.length; i++) {
View Full Code Here

Examples of it.unimi.dsi.io.ByteBufferInputStream

          termProcessor,
          field, properties, termMap, prefixMap, sizes, offsets );
    }
    else if ( queryProperties != null && queryProperties.containsKey( UriKeys.MAPPED ) ) {
      final File positionsFile = new File( basename + POSITIONS_EXTENSION );
      final ByteBufferInputStream index = ByteBufferInputStream.map( new FileInputStream( indexFile ).getChannel(), MapMode.READ_ONLY );
      return highPerformance
          ? new MemoryMappedHPIndex( index, ByteBufferInputStream.map( new FileInputStream( positionsFile ).getChannel(), MapMode.READ_ONLY ),
          numberOfDocuments, numberOfTerms, numberOfPostings, numberOfOccurrences, maxCount,
          payload, frequencyCoding, pointerCoding, countCoding, positionCoding, quantum, height,
          termProcessor,
View Full Code Here

Examples of net.yura.lobby.util.ByteBufferInputStream

            int size = -1;
            protected void onRead(final ByteBuffer buf) throws Exception {
//                byte[] bytes = new byte[ buf.remaining() ];
//                buf.get(bytes);
//                data.addBytes(bytes);
                ByteBufferInputStream data = new ByteBufferInputStream(buf);
                while (true) {
                    if (size==-1 && data.available() >= 4) {
                        size = data.readInt();
                    }
                    else if (size>=0 && data.available() >= size) {
                        Message message = (Message)access.load(data, size);
                        size = -1;
                        messageFromServer(message);
                    }
                    else {
View Full Code Here

Examples of org.apache.avro.ipc.ByteBufferInputStream

    int length = WritableUtils.readVInt(in);
    byte[] arr = new byte[length];
    in.readFully(arr);
    List<ByteBuffer> list = new ArrayList<ByteBuffer>();
    list.add(ByteBuffer.wrap(arr));
    ByteBufferInputStream is = new ByteBufferInputStream(list);

    try {
      deserializer.open(is);
      T newObj = deserializer.deserialize(obj);
      return newObj;

    }finally {
      if(deserializer != null)
        deserializer.close();
      if(is != null)
        is.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.