Search in sources :

Example 1 with LightByteArrayOutputStream

use of jetbrains.exodus.util.LightByteArrayOutputStream in project xodus by JetBrains.

the class BaseCompressTest method toString.

protected static String toString(final InputStream source) throws IOException {
    final LightByteArrayOutputStream stream = new LightByteArrayOutputStream();
    IOUtil.copyStreams(source, stream, IOUtil.BUFFER_ALLOCATOR);
    return toString(stream);
}
Also used : LightByteArrayOutputStream(jetbrains.exodus.util.LightByteArrayOutputStream)

Example 2 with LightByteArrayOutputStream

use of jetbrains.exodus.util.LightByteArrayOutputStream in project xodus by JetBrains.

the class PersistentEntityStoreImpl method setBlobString.

public void setBlobString(@NotNull final PersistentStoreTransaction txn, @NotNull final PersistentEntity entity, @NotNull final String blobName, @NotNull final String blobString) throws IOException {
    final int length = blobString.length();
    if (length == 0) {
        createBlobHandle(txn, entity, blobName, null, 0);
    } else {
        final LightByteArrayOutputStream memCopy = new LightByteArrayOutputStream();
        UTFUtil.writeUTF(memCopy, blobString);
        final int streamSize = memCopy.size();
        final ByteArraySizedInputStream copy = new ByteArraySizedInputStream(memCopy.toByteArray(), 0, streamSize);
        final long blobHandle = createBlobHandle(txn, entity, blobName, copy, streamSize);
        if (!isEmptyOrInPlaceBlobHandle(blobHandle)) {
            setBlobFileLength(txn, blobHandle, copy.size());
            txn.addBlob(blobHandle, copy);
        }
    }
}
Also used : LightByteArrayOutputStream(jetbrains.exodus.util.LightByteArrayOutputStream) ByteArraySizedInputStream(jetbrains.exodus.util.ByteArraySizedInputStream)

Example 3 with LightByteArrayOutputStream

use of jetbrains.exodus.util.LightByteArrayOutputStream in project xodus by JetBrains.

the class EntityTests method testAsciiUTFDecodingBenchmark.

public void testAsciiUTFDecodingBenchmark() {
    final String s = "This is sample ASCII string of not that great size, but large enough to use in the benchmark";
    TestUtil.time("Constructing string from data input", new Runnable() {

        @Override
        public void run() {
            try {
                final LightByteArrayOutputStream out = new LightByteArrayOutputStream();
                DataOutputStream output = new DataOutputStream(out);
                output.writeUTF(s);
                final InputStream stream = new ByteArraySizedInputStream(out.toByteArray(), 0, out.size());
                stream.mark(Integer.MAX_VALUE);
                for (int i = 0; i < 10000000; i++) {
                    stream.reset();
                    assertEquals(s, new DataInputStream(stream).readUTF());
                }
            } catch (IOException e) {
                throw ExodusException.toEntityStoreException(e);
            }
        }
    });
    TestUtil.time("Constructing strings from bytes", new Runnable() {

        @Override
        public void run() {
            final byte[] bytes = s.getBytes();
            for (int i = 0; i < 10000000; i++) {
                assertEquals(s, UTFUtil.fromAsciiByteArray(bytes, 0, bytes.length));
            }
        }
    });
}
Also used : LightByteArrayOutputStream(jetbrains.exodus.util.LightByteArrayOutputStream) ByteArraySizedInputStream(jetbrains.exodus.util.ByteArraySizedInputStream) ByteArraySizedInputStream(jetbrains.exodus.util.ByteArraySizedInputStream)

Aggregations

LightByteArrayOutputStream (jetbrains.exodus.util.LightByteArrayOutputStream)3 ByteArraySizedInputStream (jetbrains.exodus.util.ByteArraySizedInputStream)2