Search in sources :

Example 1 with BufferManager

use of com.amazon.ion.impl.IonBinary.BufferManager in project ion-java by amzn.

the class ByteBufferTest method testLargeInsertion.

@Test
public void testLargeInsertion() {
    BufferManager buf = new BufferManager();
    IonBinary.Writer writer = buf.openWriter();
    // Write enough data to overflow the first block
    byte[] initialData = new byte[BlockedBuffer._defaultBlockSizeMin + 5];
    // Now insert lots of stuff at the beginning
    try {
        writer.write(initialData, 0, initialData.length);
        writer.setPosition(0);
        writer.insert(5000);
    } catch (IOException e) {
        throw new IonException(e);
    }
}
Also used : IonException(com.amazon.ion.IonException) IOException(java.io.IOException) BufferManager(com.amazon.ion.impl.IonBinary.BufferManager) Test(org.junit.Test)

Example 2 with BufferManager

use of com.amazon.ion.impl.IonBinary.BufferManager in project ion-java by amzn.

the class _Private_Utils method loadStreamBytes.

public static byte[] loadStreamBytes(InputStream in) throws IOException {
    BufferManager buffer = new BufferManager(in);
    Reader bufReader = buffer.reader();
    bufReader.sync();
    bufReader.setPosition(0);
    byte[] bytes = bufReader.getBytes();
    return bytes;
}
Also used : Reader(com.amazon.ion.impl.IonBinary.Reader) IonReader(com.amazon.ion.IonReader) BufferManager(com.amazon.ion.impl.IonBinary.BufferManager)

Example 3 with BufferManager

use of com.amazon.ion.impl.IonBinary.BufferManager in project ion-java by amzn.

the class ByteBufferTest method testSmallInsertion.

@Test
public void testSmallInsertion() {
    BufferManager buf = new BufferManager();
    IonBinary.Writer writer = buf.openWriter();
    // Write enough data to overflow the first block
    byte[] initialData = new byte[BlockedBuffer._defaultBlockSizeMin + 5];
    // Now insert some stuff at the beginning
    try {
        writer.write(initialData, 0, initialData.length);
        writer.setPosition(0);
        writer.insert(10);
    } catch (IOException e) {
        throw new IonException(e);
    }
}
Also used : IonException(com.amazon.ion.IonException) IOException(java.io.IOException) BufferManager(com.amazon.ion.impl.IonBinary.BufferManager) Test(org.junit.Test)

Example 4 with BufferManager

use of com.amazon.ion.impl.IonBinary.BufferManager in project ion-java by amzn.

the class ByteBufferTest method testUnicodeCodepointOverflow.

@Test
public void testUnicodeCodepointOverflow() {
    BufferManager buf = new BufferManager();
    IonBinary.Writer writer = buf.openWriter();
    try {
        writer.writeStringData(new String(new char[] { 0xd799 }, 0, 1));
        writer.writeStringData(new String(new char[] { 0xe000 }, 0, 1));
    } catch (Exception e) {
        fail("Unexpected exception: " + e.getMessage());
    }
    try {
        writer.writeStringData(new String(new char[] { 0xd800 }, 0, 1));
        fail("Successfully parsed a partial surrogate");
    } catch (Exception e) {
    }
    try {
        writer.writeStringData(new String(new char[] { 0xdfff }, 0, 1));
        fail("Successfully parsed a partial surrogate");
    } catch (Exception e) {
    }
}
Also used : BufferManager(com.amazon.ion.impl.IonBinary.BufferManager) IOException(java.io.IOException) IonException(com.amazon.ion.IonException) Test(org.junit.Test)

Aggregations

BufferManager (com.amazon.ion.impl.IonBinary.BufferManager)4 IonException (com.amazon.ion.IonException)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 IonReader (com.amazon.ion.IonReader)1 Reader (com.amazon.ion.impl.IonBinary.Reader)1