Package java.nio

Examples of java.nio.ByteBuffer.asReadOnlyBuffer()


   * Constructs a new read-only {@code java.nio.ByteBuffer} with the
   * same backing byte array.
   */
  public ByteBuffer asReadOnlyByteBuffer() {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    return byteBuffer.asReadOnlyBuffer();
  }

  /**
   * Constructs a new {@code String} by decoding the bytes using the
   * specified charset.
View Full Code Here


  @Override
  public ByteBuffer asReadOnlyByteBuffer() {
    ByteBuffer byteBuffer =
        ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size());
    return byteBuffer.asReadOnlyBuffer();
  }

  @Override
  public List<ByteBuffer> asReadOnlyByteBufferList() {
    // Return the ByteBuffer generated by asReadOnlyByteBuffer() as a singleton
View Full Code Here

  }

  @Override
  public ByteBuffer asReadOnlyByteBuffer() {
    ByteBuffer byteBuffer = ByteBuffer.wrap(toByteArray());
    return byteBuffer.asReadOnlyBuffer();
  }

  @Override
  public List<ByteBuffer> asReadOnlyByteBufferList() {
    // Walk through the list of LiteralByteString's that make up this
View Full Code Here

    public void test_read_LByteBuffer_readOnlyBuf() throws Exception {
        // regression test for Harmony-754
        ByteBuffer c = ByteBuffer.allocate(1);
        DatagramChannel channel = DatagramChannel.open();
        try{
            channel.read(c.asReadOnlyBuffer());
            fail("Should throw NotYetConnectedException");
        } catch (NotYetConnectedException e){
            // expected
        }
        channel.connect(localAddr1);
View Full Code Here

        } catch (NotYetConnectedException e){
            // expected
        }
        channel.connect(localAddr1);
        try{
            channel.read(c.asReadOnlyBuffer());
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e){
            // expected
        }
    }
View Full Code Here

        for (int n = 0, ii = esi; n < numSymbols; n++, ii++) {
            symbols.put(getSourceSymbol(ii).transportData());
        }
        symbols.flip();

        return EncodingPacket.newSourcePacket(sbn, esi, symbols.asReadOnlyBuffer(), numSymbols);
    }

    @Override
    public EncodingPacket repairPacket(int esi) {
View Full Code Here

        for (int i = 0; i < numSymbols; i++) {
            symbols.put(getRepairSymbol(esi + i).readOnlyData());
        }
        symbols.flip();

        return EncodingPacket.newRepairPacket(sbn, esi, symbols.asReadOnlyBuffer(), numSymbols);
    }

    @Override
    public IterableBuilder newIterableBuilder() {
View Full Code Here

      buffer.put(intAsBytes, intAsBytes.length - numBytes, numBytes);
      ++i;
    }
    buffer.position(0);

    return new VSizeIndexedInts(buffer.asReadOnlyBuffer(), numBytes);
  }

  public static byte getNumBytesForMax(int maxValue)
  {
    if (maxValue < 0) {
View Full Code Here

        ByteBuffer ret = b.slice();
        ret.limit(PAGE_SIZE);
        if(!transactionsDisabled||readonly){
            // changes written into buffer will be directly written into file
            // so we need to protect buffer from modifications
            ret = ret.asReadOnlyBuffer();
        }
        return ret;
    }

    public void forceClose() throws IOException {
View Full Code Here

            //out of bounds, so just return empty data
            return ByteBuffer.wrap(PageFile.CLEAN_DATA).asReadOnlyBuffer();
        }else{
            ByteBuffer b = ByteBuffer.wrap(data);
            if(!transactionsDisabled)
                return b.asReadOnlyBuffer();
            else
                return b;
        }

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.