當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadOnlyBufferException類代碼示例

本文整理匯總了Java中java.nio.ReadOnlyBufferException的典型用法代碼示例。如果您正苦於以下問題:Java ReadOnlyBufferException類的具體用法?Java ReadOnlyBufferException怎麽用?Java ReadOnlyBufferException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ReadOnlyBufferException類屬於java.nio包,在下文中一共展示了ReadOnlyBufferException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readOnly

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
@Test
public void readOnly() throws Exception {
    assertFalse(Bytes.from(example_bytes_twentyfour).isReadOnly());
    assertTrue(Bytes.from(example_bytes_twentyfour).readOnly().isReadOnly());
    assertTrue(Bytes.from(example_bytes_twentyfour).readOnly().copy().isReadOnly());

    assertArrayEquals(example_bytes_twentyfour, Bytes.from(example_bytes_twentyfour).readOnly().internalArray());
    try {
        Bytes.from(example_bytes_twentyfour).readOnly().array();
        fail();
    } catch (ReadOnlyBufferException e) {
    }

    Bytes b = Bytes.from(example_bytes_twentyfour).readOnly();
    assertSame(b, b.readOnly());
}
 
開發者ID:patrickfav,項目名稱:bytes-java,代碼行數:17,代碼來源:BytesMiscTest.java

示例2: putString

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
public static void putString(ByteBuffer buffer, String str, Charset charset) throws BufferOverflowException, ReadOnlyBufferException {
    if (str == null || str.isEmpty())
        putCompactInt(buffer, 0);
    else if (charset != null)
        putBytes(buffer, str, charset);
    else {
        try {
            if (defaultCharset.newEncoder().canEncode(str)) {
                putBytes(buffer, str, defaultCharset);
                return;
            }
        } catch (UnsupportedOperationException ignore) {
        }
        putChars(buffer, str);
    }
}
 
開發者ID:acmi,項目名稱:L2io,代碼行數:17,代碼來源:BufferUtil.java

示例3: testGetReadOnlyDst

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
private void testGetReadOnlyDst(boolean direct) {
    byte[] bytes = { 'a', 'b', 'c', 'd' };

    ByteBuf buffer = newBuffer(bytes.length);
    buffer.writeBytes(bytes);

    ByteBuffer dst = direct ? ByteBuffer.allocateDirect(bytes.length) : ByteBuffer.allocate(bytes.length);
    ByteBuffer readOnlyDst = dst.asReadOnlyBuffer();
    try {
        buffer.getBytes(0, readOnlyDst);
        fail();
    } catch (ReadOnlyBufferException e) {
        // expected
    }
    assertEquals(0, readOnlyDst.position());
    buffer.release();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:18,代碼來源:AbstractByteBufTest.java

示例4: encode

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
private static void encode(CharSequence paramCharSequence, ByteBuffer paramByteBuffer)
{
  if (paramByteBuffer.isReadOnly()) {
    throw new ReadOnlyBufferException();
  }
  if (paramByteBuffer.hasArray()) {
    try
    {
      paramByteBuffer.position(encode(paramCharSequence, paramByteBuffer.array(), paramByteBuffer.arrayOffset() + paramByteBuffer.position(), paramByteBuffer.remaining()) - paramByteBuffer.arrayOffset());
      return;
    }
    catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)
    {
      BufferOverflowException localBufferOverflowException = new BufferOverflowException();
      localBufferOverflowException.initCause(localArrayIndexOutOfBoundsException);
      throw localBufferOverflowException;
    }
  }
  encodeDirect(paramCharSequence, paramByteBuffer);
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:21,代碼來源:CodedOutputByteBufferNano.java

示例5: zza

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
private static void zza(CharSequence paramCharSequence, ByteBuffer paramByteBuffer)
{
  if (paramByteBuffer.isReadOnly()) {
    throw new ReadOnlyBufferException();
  }
  if (paramByteBuffer.hasArray()) {
    try
    {
      paramByteBuffer.position(zza(paramCharSequence, paramByteBuffer.array(), paramByteBuffer.arrayOffset() + paramByteBuffer.position(), paramByteBuffer.remaining()) - paramByteBuffer.arrayOffset());
      return;
    }
    catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)
    {
      BufferOverflowException localBufferOverflowException = new BufferOverflowException();
      localBufferOverflowException.initCause(localArrayIndexOutOfBoundsException);
      throw localBufferOverflowException;
    }
  }
  zzb(paramCharSequence, paramByteBuffer);
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:21,代碼來源:zzaic.java

示例6: a

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
private static void a(CharSequence paramCharSequence, ByteBuffer paramByteBuffer)
{
  if (paramByteBuffer.isReadOnly()) {
    throw new ReadOnlyBufferException();
  }
  if (paramByteBuffer.hasArray()) {
    try
    {
      paramByteBuffer.position(a(paramCharSequence, paramByteBuffer.array(), paramByteBuffer.arrayOffset() + paramByteBuffer.position(), paramByteBuffer.remaining()) - paramByteBuffer.arrayOffset());
      return;
    }
    catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)
    {
      BufferOverflowException localBufferOverflowException = new BufferOverflowException();
      localBufferOverflowException.initCause(localArrayIndexOutOfBoundsException);
      throw localBufferOverflowException;
    }
  }
  b(paramCharSequence, paramByteBuffer);
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:21,代碼來源:qal.java

示例7: encode

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
/**
 * Encodes {@code sequence} into UTF-8, in {@code byteBuffer}. For a string, this method is
 * equivalent to {@code buffer.put(string.getBytes(UTF_8))}, but is more efficient in both time
 * and space. Bytes are written starting at the current position. This method requires paired
 * surrogates, and therefore does not support chunking.
 *
 * <p>To ensure sufficient space in the output buffer, either call {@link #encodedLength} to
 * compute the exact amount needed, or leave room for {@code 3 * sequence.length()}, which is the
 * largest possible number of bytes that any input can be encoded to.
 *
 * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired
 *     surrogates)
 * @throws BufferOverflowException if {@code sequence} encoded in UTF-8 does not fit in
 *     {@code byteBuffer}'s remaining space.
 * @throws ReadOnlyBufferException if {@code byteBuffer} is a read-only buffer.
 */
private static void encode(CharSequence sequence, ByteBuffer byteBuffer) {
  if (byteBuffer.isReadOnly()) {
    throw new ReadOnlyBufferException();
  } else if (byteBuffer.hasArray()) {
    try {
      int encoded = encode(sequence,
              byteBuffer.array(),
              byteBuffer.arrayOffset() + byteBuffer.position(),
              byteBuffer.remaining());
      byteBuffer.position(encoded - byteBuffer.arrayOffset());
    } catch (ArrayIndexOutOfBoundsException e) {
      BufferOverflowException boe = new BufferOverflowException();
      boe.initCause(e);
      throw boe;
    }
  } else {
    encodeDirect(sequence, byteBuffer);
  }
}
 
開發者ID:IvanVolosyuk,項目名稱:diskusage,代碼行數:36,代碼來源:CodedOutputByteBufferNano.java

示例8: calcDstsLength

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
private static int calcDstsLength(ByteBuffer[] dsts, int dstsOffset, int dstsLength) {
    int capacity = 0;
    for (int i = 0; i < dsts.length; i++) {
        ByteBuffer dst = dsts[i];
        checkArgument(dst != null, "dsts[%d] is null", i);
        if (dst.isReadOnly()) {
            throw new ReadOnlyBufferException();
        }
        if (i >= dstsOffset && i < dstsOffset + dstsLength) {
            capacity += dst.remaining();
        }
    }
    return capacity;
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:15,代碼來源:ConscryptEngine.java

示例9: putBytes

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
public static void putBytes(ByteBuffer buffer, String str, Charset charset) throws BufferOverflowException, ReadOnlyBufferException {
    if (str == null || str.isEmpty())
        putCompactInt(buffer, 0);
    else {
        byte[] strBytes = (str + '\0').getBytes(charset);
        putCompactInt(buffer, strBytes.length);
        buffer.put(strBytes);
    }
}
 
開發者ID:acmi,項目名稱:L2io,代碼行數:10,代碼來源:BufferUtil.java

示例10: putChars

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
public static void putChars(ByteBuffer buffer, String str) throws BufferOverflowException, ReadOnlyBufferException {
    if (str == null || str.isEmpty())
        putCompactInt(buffer, 0);
    else {
        byte[] strBytes = (str + '\0').getBytes(UTF16LE);
        putCompactInt(buffer, -strBytes.length);
        buffer.put(strBytes);
    }
}
 
開發者ID:acmi,項目名稱:L2io,代碼行數:10,代碼來源:BufferUtil.java

示例11: putUTF

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
public static void putUTF(ByteBuffer buffer, String str) throws BufferOverflowException, ReadOnlyBufferException {
    if (str == null || str.isEmpty()) {
        buffer.putInt(0);
    } else {
        byte[] bytes = str.getBytes(UTF16LE);
        buffer.putInt(bytes.length);
        buffer.put(bytes);
    }
}
 
開發者ID:acmi,項目名稱:L2io,代碼行數:10,代碼來源:BufferUtil.java

示例12: testForwarding

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
public void testForwarding() {
    GrowableByteBuffer g = new GrowableByteBuffer(1063);
    int first = g.arrayOffset();
    g.put(0, (byte) 37);
    assertTrue(g.hasArray());
    assertEquals((byte) 37, g.array()[first]);
    g.putChar(0, 'a');
    assertEquals('a', g.getChar(0));
    assertEquals('a', g.asCharBuffer().get(0));
    g.putDouble(0, 10.0d);
    assertEquals(10.0d, g.getDouble(0));
    assertEquals(10.0d, g.asDoubleBuffer().get(0));
    g.putFloat(0, 10.0f);
    assertEquals(10.0f, g.getFloat(0));
    assertEquals(10.0f, g.asFloatBuffer().get(0));
    g.putInt(0, 10);
    assertEquals(10, g.getInt(0));
    assertEquals(10, g.asIntBuffer().get(0));
    g.putLong(0, 10L);
    assertEquals(10L, g.getLong(0));
    assertEquals(10L, g.asLongBuffer().get(0));
    boolean caught = false;
    try {
        g.asReadOnlyBuffer().put((byte) 10);
    } catch (ReadOnlyBufferException e) {
        caught = true;
    }
    assertTrue(caught);
    g.putShort(0, (short) 10);
    assertEquals((short) 10, g.getShort(0));
    assertEquals((short) 10, g.asShortBuffer().get(0));
    g.position(0);
    g.put((byte) 0);
    g.put((byte) 10);
    g.limit(2);
    g.position(1);
    g.compact();
    assertEquals((byte) 10, g.get(0));
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:40,代碼來源:GrowableByteBufferTestCase.java

示例13: ensureWritable

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
@Override
public ByteBuf ensureWritable(int minWritableBytes) {
	// note: ReadOnlyByteBuf allows this but in most cases this does not make sense
	if (minWritableBytes != 0) {
		throw new ReadOnlyBufferException();
	}
	return this;
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:9,代碼來源:ReadOnlySlicedNetworkBuffer.java

示例14: testSetInt

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
@Test(expected = ReadOnlyBufferException.class)
public void testSetInt() {
    ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
    buffers.add(buf);

    buf.setInt(0, 1);
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:8,代碼來源:ReadOnlyDirectByteBufferBufTest.java

示例15: testSetBytesViaStream

import java.nio.ReadOnlyBufferException; //導入依賴的package包/類
@Test(expected = ReadOnlyBufferException.class)
public void testSetBytesViaStream() throws IOException {
    ByteBuf buf = buffer(ByteBuffer.allocateDirect(8).asReadOnlyBuffer());
    buffers.add(buf);
    buf.setBytes(0, new ByteArrayInputStream("test".getBytes()), 2);
    buf.release();
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:8,代碼來源:ReadOnlyDirectByteBufferBufTest.java


注:本文中的java.nio.ReadOnlyBufferException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。