net.jpountz.lz4.LZ4BlockInputStream Java Examples

The following examples show how to use net.jpountz.lz4.LZ4BlockInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Lz4Compress.java    From compress with MIT License 6 votes vote down vote up
@Override
public byte[] uncompress(byte[] data) throws IOException {
	LZ4Factory factory = LZ4Factory.fastestInstance();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	LZ4FastDecompressor decompresser = factory.fastDecompressor();
	LZ4BlockInputStream lzis = new LZ4BlockInputStream(new ByteArrayInputStream(data), decompresser);
	
	int count;
	byte[] buffer = new byte[2048];
	while ((count = lzis.read(buffer)) != -1) {
		baos.write(buffer, 0, count);
	}
	lzis.close();
	
	return baos.toByteArray();
}
 
Example #2
Source File: MCAFile2LevelDB.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void close() throws IOException {
    try {
        this.os.close();

        FaweInputStream in = new FaweInputStream(new ZstdInputStream(new LZ4BlockInputStream(new BufferedInputStream(new FileInputStream(file)))));
        for (int i = 0; i < numKeys; i++) {
            int len = in.readVarInt();
            byte[] key = new byte[len];
            in.readFully(key);

            len = in.readVarInt();
            byte[] value = new byte[len];
            in.readFully(value);
            db.put(key, value);
        }
        in.close();
        file.delete();
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
 
Example #3
Source File: XmlTransformer.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
public final InputStream transform( final InputStream inputStream ) {
	try {
		// Since these files can become pretty big, storing them in memory might lead to OutOfMemoryErrors.
		final File tmpFile = File.createTempFile( "retest-migration-", ".xml.lz4" );
		tmpFile.deleteOnExit();
		logger.debug( "Creating temporary file '{}' for XML migration. File will be deleted upon exit.",
				canonicalPathQuietly( tmpFile ) );

		convertAndWriteToFile( inputStream, tmpFile );
		return new LZ4BlockInputStream( new DeleteOnCloseFileInputStream( tmpFile ) );
	} catch ( final IOException e ) {
		throw new RuntimeException( e );
	}
}
 
Example #4
Source File: DecompressionStreamChainer.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
@Override
public final InputStream chainInput(final InputStream in) throws IOException {
  switch (compression) {
    case GZIP:
      return new GZIPInputStream(in);
    case LZ4:
      return new LZ4BlockInputStream(in);
    case NONE:
      return in;
    default:
      throw new UnsupportedCompressionException("Not supported compression method");
  }
}
 
Example #5
Source File: DiskArrayList.java    From herddb with Apache License 2.0 5 votes vote down vote up
private void openReader() {
    if (!written) {
        throw new IllegalStateException("prima bisogna riempire la lista e chiamare finish()");
    }
    if (writing) {
        throw new IllegalStateException("scrittura ancora in corso");
    }
    if (!swapped) {
        throw new IllegalStateException("scrittura non avvenuta");
    }
    if (in != null) {
        // rewind support
        closeReader();
    }
    try {
        in = Files.newInputStream(tmpFile);
        bin = new BufferedInputStream(in, DISK_BUFFER_SIZE);
        if (compressionEnabled) {
            zippedin = new LZ4BlockInputStream(bin);
            oin = new ExtendedDataInputStream(zippedin);
        } else {
            oin = new ExtendedDataInputStream(bin);
        }
        countread = 0;
    } catch (IOException err) {
        closeReader();
        throw new RuntimeException(err);
    }

}
 
Example #6
Source File: CompressionStreamChainer.java    From nemo with Apache License 2.0 5 votes vote down vote up
@Override
public final InputStream chainInput(final InputStream in) throws IOException {
  switch (compression) {
    case Gzip:
      return new GZIPInputStream(in);
    case LZ4:
      return new LZ4BlockInputStream(in);
    default:
      throw new UnsupportedCompressionException("Not supported compression method");
  }
}
 
Example #7
Source File: StreamChange.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
default void undoChanges(File file) throws IOException {
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
        try (LZ4BlockInputStream compressed = new LZ4BlockInputStream(in)) {
            try (FaweInputStream fis = new FaweInputStream(compressed)) {
                undoChanges(fis);
            }
        }
    }
}
 
Example #8
Source File: StreamChange.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
default void redoChanges(File file) throws IOException {
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
        try (LZ4BlockInputStream compressed = new LZ4BlockInputStream(in)) {
            try (FaweInputStream fis = new FaweInputStream(compressed)) {
                redoChanges(fis);
            }
        }
    }
}
 
Example #9
Source File: TextFile.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public final void open() throws IOException {
		
		if (!file.exists() && !writeable) {
			throw new IOException("Could not find file: " + file);
		} else {
			if (writeable) {
				if (uselz4) {
					
					LZ4BlockOutputStream os = new LZ4BlockOutputStream(new FileOutputStream(file), buffersize);
					out = new BufferedWriter(new OutputStreamWriter(os,"US-ASCII"), buffersize);
					
				} else if (gzipped) {
//					ParallelGZIPOutputStream gzipOutputStream = new ParallelGZIPOutputStream(new FileOutputStream(file), buffersize));
					GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(file), buffersize) {{
						def.setLevel(Deflater.BEST_SPEED);
					}};
					out = new BufferedWriter(new OutputStreamWriter(gzipOutputStream, "US-ASCII"), buffersize);
					
				} else {
					out = new BufferedWriter(new FileWriter(file), buffersize);
				}
			} else {
				if (uselz4) {
					LZ4BlockInputStream is = new LZ4BlockInputStream(new FileInputStream(file));
					in = new BufferedReader(new InputStreamReader(is, "US-ASCII"));
				} else if (gzipped) {
					GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(file), buffersize);
					in = new BufferedReader(new InputStreamReader(gzipInputStream, "US-ASCII"));
				} else {
//                System.out.println("Opening file: "+file);
					in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING), buffersize);
				}
			}
		}
	}
 
Example #10
Source File: FastLzRunner.java    From x-pipe with Apache License 2.0 4 votes vote down vote up
@Override
protected InputStream getDecompressInputStream(InputStream inputStream) {
    return new LZ4BlockInputStream(inputStream);
}
 
Example #11
Source File: IncomingTcpConnection.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private void receiveMessages() throws IOException
{
    // handshake (true) endpoint versions
    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
    out.writeInt(MessagingService.current_version);
    out.flush();
    DataInputStream in = new DataInputStream(socket.getInputStream());
    int maxVersion = in.readInt();

    from = CompactEndpointSerializationHelper.deserialize(in);
    // record the (true) version of the endpoint
    MessagingService.instance().setVersion(from, maxVersion);
    logger.debug("Set version for {} to {} (will use {})", from, maxVersion, MessagingService.instance().getVersion(from));

    if (compressed)
    {
        logger.debug("Upgrading incoming connection to be compressed");
        if (version < MessagingService.VERSION_21)
        {
            in = new DataInputStream(new SnappyInputStream(socket.getInputStream()));
        }
        else
        {
            LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
            Checksum checksum = XXHashFactory.fastestInstance().newStreamingHash32(OutboundTcpConnection.LZ4_HASH_SEED).asChecksum();
            in = new DataInputStream(new LZ4BlockInputStream(socket.getInputStream(),
                                                             decompressor,
                                                             checksum));
        }
    }
    else
    {
        in = new DataInputStream(new BufferedInputStream(socket.getInputStream(), BUFFER_SIZE));
    }

    if (version > MessagingService.current_version)
    {
        // save the endpoint so gossip will reconnect to it
        Gossiper.instance.addSavedEndpoint(from);
        logger.info("Received messages from newer protocol version {}. Ignoring", version);
        return;
    }
    // outbound side will reconnect if necessary to upgrade version

    while (true)
    {
        MessagingService.validateMagic(in.readInt());
        receiveMessage(in, version);
    }
}