[ https://issues.apache.org/jira/browse/BEAM-8564?focusedWorklogId=353838&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-353838 ]
ASF GitHub Bot logged work on BEAM-8564: ---------------------------------------- Author: ASF GitHub Bot Created on: 04/Dec/19 22:07 Start Date: 04/Dec/19 22:07 Worklog Time Spent: 10m Work Description: gsteelman commented on pull request #10254: [BEAM-8564] Add LZO compression and decompression support URL: https://github.com/apache/beam/pull/10254#discussion_r354009344 ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/util/LzoCompressorInputStream.java ########## @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.util; + +import io.airlift.compress.lzo.LzoCodec; +import java.io.IOException; +import java.io.InputStream; +import org.apache.commons.compress.compressors.CompressorInputStream; +import org.apache.commons.compress.utils.CountingInputStream; +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.compress.utils.InputStreamStatistics; + +/** + * {@link CompressorInputStream} implementation to create LZO encoded stream. Library relies on <a + * href="https://github.com/airlift/aircompressor/">LZO</a> + * + * @since 1.18 + */ +public class LzoCompressorInputStream extends CompressorInputStream + implements InputStreamStatistics { + + private final CountingInputStream countingStream; + private final InputStream lzoIS; + + /** + * Wraps the given stream into a aircompressor's HadoopLzoInputStream using the LzoCodec. + * + * @param inStream the stream to write to + * @throws IOException if aircompressor does + */ + public LzoCompressorInputStream(final InputStream inStream) throws IOException { + this.lzoIS = + new LzoCodec().createInputStream(countingStream = new CountingInputStream(inStream)); + } + + @Override + public int available() throws IOException { + return lzoIS.available(); + } + + @Override + public void close() throws IOException { + lzoIS.close(); + } + + @Override + public int read(final byte[] b) throws IOException { + return read(b, 0, b.length); + } + + @Override + public long skip(final long n) throws IOException { + return IOUtils.skip(lzoIS, n); + } + + @Override + public void mark(final int readlimit) { + lzoIS.mark(readlimit); + } + + @Override + public boolean markSupported() { + return lzoIS.markSupported(); + } + + @Override + public int read() throws IOException { + final int ret = lzoIS.read(); + count(ret == -1 ? 0 : 1); + return ret; + } + + @Override + public int read(final byte[] buf, final int off, final int len) throws IOException { + if (len == 0) { + return 0; + } + final int ret = lzoIS.read(buf, off, len); Review comment: What is the reason for not delegating the call in the case of 0 length? Does `lzoIS.read()` not handle that case cleanly? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 353838) Time Spent: 1h 10m (was: 1h) > Add LZO compression and decompression support > --------------------------------------------- > > Key: BEAM-8564 > URL: https://issues.apache.org/jira/browse/BEAM-8564 > Project: Beam > Issue Type: New Feature > Components: sdk-java-core > Reporter: Amogh Tiwari > Assignee: Amogh Tiwari > Priority: Minor > Time Spent: 1h 10m > Remaining Estimate: 0h > > LZO is a lossless data compression algorithm which is focused on compression > and decompression speeds. > This will enable Apache Beam sdk to compress/decompress files using LZO > compression algorithm. > This will include the following functionalities: > # compress() : for compressing files into an LZO archive > # decompress() : for decompressing files archived using LZO compression > Appropriate Input and Output stream will also be added to enable working with > LZO files. -- This message was sent by Atlassian Jira (v8.3.4#803005)