Package java.nio

Examples of java.nio.ByteBuffer.rewind()


    public void verifyThatTrailingSpacesAreRemovedFromHeader() throws UnsupportedEncodingException,
            ProtocolDecoderException {
        String reqStr = "GET / HTTP/1.0\r\nHost:localhost  \r\n\r\n";
        ByteBuffer buffer = ByteBuffer.allocate(reqStr.length());
        buffer.put(reqStr.getBytes("US-ASCII"));
        buffer.rewind();
        HttpServerDecoder decoder = new HttpServerDecoder();
        HttpDecoderState state = decoder.createDecoderState();
        HttpPdu pdus = decoder.decode(buffer, state);
        assertNotNull(pdus);
        assertEquals("localhost", ((HttpRequestImpl) pdus).getHeader("host"));
View Full Code Here


          inMemory);
      bucketEntry.setDeserialiserReference(data.getDeserializer(), deserialiserMap);
      try {
        if (data instanceof HFileBlock) {
          ByteBuffer sliceBuf = ((HFileBlock) data).getBufferReadOnlyWithHeader();
          sliceBuf.rewind();
          assert len == sliceBuf.limit() + HFileBlock.EXTRA_SERIALIZATION_SPACE;
          ByteBuffer extraInfoBuffer = ByteBuffer.allocate(HFileBlock.EXTRA_SERIALIZATION_SPACE);
          ((HFileBlock) data).serializeExtraInfo(extraInfoBuffer);
          ioEngine.write(sliceBuf, offset);
          ioEngine.write(extraInfoBuffer, offset + len - HFileBlock.EXTRA_SERIALIZATION_SPACE);
View Full Code Here

        throw new IOException("Meta magic is bad in block " + block);
      }
      // Toss the header. May have to remove later due to performance.
      buf.compact();
      buf.limit(buf.limit() - METABLOCKMAGIC.length);
      buf.rewind();
      return buf;
    }

    /**
     * Read in a file block.
View Full Code Here

          throw new IOException("Data magic is bad in block " + block);
        }
        // Toss the header. May have to remove later due to performance.
        buf.compact();
        buf.limit(buf.limit() - DATABLOCKMAGIC.length);
        buf.rewind();

        readTime += System.currentTimeMillis() - now;
        readOps++;

        // Cache the block
View Full Code Here

        if (this.block == null || this.currKeyLen == 0) {
          throw new RuntimeException("you need to seekTo() before calling getKey()");
        }
        ByteBuffer keyBuff = this.block.slice();
        keyBuff.limit(this.currKeyLen);
        keyBuff.rewind();
        // Do keyBuff.asReadOnly()?
        return keyBuff;
      }

      public ByteBuffer getValue() {
View Full Code Here

        // TODO: Could this be done with one ByteBuffer rather than create two?
        ByteBuffer valueBuff = this.block.slice();
        valueBuff.position(this.currKeyLen);
        valueBuff = valueBuff.slice();
        valueBuff.limit(currValueLen);
        valueBuff.rewind();
        return valueBuff;
      }

      public boolean next() throws IOException {
        // LOG.deug("rem:" + block.remaining() + " p:" + block.position() +
View Full Code Here

      for (int j = 0; j < DEFAULT_RESPONSE_CHUNK_SIZE / patternSize; ++j)
      {
        bb.put(BODY_PATTERN.getBytes(Charset.defaultCharset()));
      }

          bb.rewind();
      request.getResponseContent().write(bb);
    }

    if (respSize % DEFAULT_RESPONSE_CHUNK_SIZE > 0)
    {
View Full Code Here

        // TODO: Move CRC calculation in BasicHeaderSegment.serialize?
        if (basicHeaderSegment.getParser().canHaveDigests()) {
            offset += serializeDigest(pdu, dataDigest);
        }

        return (ByteBuffer) pdu.rewind();
    }

    /**
     * Deserializes (parses) a given byte representation of a PDU to an PDU object.
     *
 
View Full Code Here

      // We allocate a byte buffer of transfer length and write either all input data
      // or up to the transfer length in input data.
      ByteBuffer data = ByteBuffer.allocate((int) Math.min(transferLength, input.length));
      data.put(input, 0, (int) Math.min(transferLength, input.length));
      data.rewind();

      if (Thread.interrupted())
         throw new InterruptedException();

      return this.targetTransportPort.writeData(this.command.getNexus(),
View Full Code Here

        final ByteBuffer expectedResult = ByteBuffer.wrap(TEST_CASE_1_ARRAY_LONG);
        dataSegment.dataBuffer.rewind();

        final ByteBuffer exportedDataSegment = ByteBuffer.allocate(AbstractDataSegment.getTotalLength(dataSegment.getLength()));
        dataSegment.serialize(exportedDataSegment, 0);
        exportedDataSegment.rewind();

        assertTrue(expectedResult.equals(exportedDataSegment));
    }

    /**
 
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.