Package org.iq80.leveldb.util

Examples of org.iq80.leveldb.util.Slice


    {
        int raw = (int) (len * compressionRatio);
        if (raw < 1) {
            raw = 1;
        }
        Slice rawData = generateRandomSlice(rnd, raw);

        // Duplicate the random data until we have filled "len" bytes
        Slice dst = Slices.allocate(len);
        SliceOutput sliceOutput = dst.output();
        while (sliceOutput.size() < len) {
            sliceOutput.writeBytes(rawData, 0, Math.min(rawData.length(), sliceOutput.writableBytes()));
        }
        return dst;
    }
View Full Code Here


        return dst;
    }

    private static Slice generateRandomSlice(Random random, int length)
    {
        Slice rawData = Slices.allocate(length);
        SliceOutput sliceOutput = rawData.output();
        while (sliceOutput.isWritable()) {
            sliceOutput.writeByte((byte) ((int) ' ' + random.nextInt(95)));
        }
        return rawData;
    }
View Full Code Here

        {
            if (position + length > data.length()) {
                position = 0;
                assert (length < data.length());
            }
            Slice slice = data.slice(position, length);
            position += length;
            return slice.getBytes();
        }
View Full Code Here

    protected OutputStream wrapOutputStream(OutputStream underlying) throws IOException {
        return new SnappyOutputStream(underlying);
    }

    protected InputStream wrapInputStream(InputStream underlying) throws IOException {
        return new SnappyInputStream(underlying);
    }
View Full Code Here

        snappyOutputStream.close();
    }

    public static ChannelBuffer decompress(ChannelBuffer in) throws IOException {
        ChannelBufferInputStream channelBufferInputStream = new ChannelBufferInputStream(in);
        SnappyInputStream inputStream = new SnappyInputStream(channelBufferInputStream);
        ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(ByteStreams.toByteArray(inputStream));
        return channelBuffer;
    }
View Full Code Here

        return channelBuffer;
    }

    public static byte[] decompress(byte[] in) throws IOException {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(in);
        SnappyInputStream inputStream = new SnappyInputStream(byteArrayInputStream);
        return ByteStreams.toByteArray(inputStream);
    }
View Full Code Here

    public static <T> T decode(byte[] cryptedBytes, Class<T> clazz) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, DecoderException, IOException {
        byte[] bytes = cipherDecrypt.get().doFinal(cryptedBytes);


        SnappyInputStream snappyInputStream = new SnappyInputStream(new ByteArrayInputStream(bytes));


        //MessagePack messagePack = new MessagePack();
        return messagePack.read(ByteStreams.toByteArray(snappyInputStream), clazz);
    }
View Full Code Here

    public String getType() {
        return "snappy";
    }

    protected OutputStream wrapOutputStream(OutputStream underlying) throws IOException {
        return new SnappyOutputStream(underlying);
    }
View Full Code Here

        return byteArrayOutputStream.toByteArray();
    }

    public static void compress(byte[] in, OutputStream out) throws IOException {
        SnappyOutputStream snappyOutputStream = new SnappyOutputStream(out);
        snappyOutputStream.write(in);
        snappyOutputStream.close();
    }
View Full Code Here

        byte[] origBytes = messagePack.write(object);
        System.out.println("orig length: " + origBytes.length);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SnappyOutputStream snappyOutputStream = new SnappyOutputStream(out);
        snappyOutputStream.write(origBytes);
        snappyOutputStream.close();

        byte[] comressedBytes = out.toByteArray();
        System.out.println("comressedBytes length: " + comressedBytes.length);

        byte[] bytes = cipherEncrypt.get().doFinal(comressedBytes);
View Full Code Here

TOP

Related Classes of org.iq80.leveldb.util.Slice

Copyright © 2018 www.massapicom. 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.