forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd36c75
commit 0bd4451
Showing
9 changed files
with
822 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
sdks/java/core/src/main/java/org/apache/beam/sdk/util/LzoCompressorInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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; | ||
|
||
public class LzoCompressorInputStream extends CompressorInputStream | ||
implements InputStreamStatistics { | ||
|
||
private final CountingInputStream countingStream; | ||
private final InputStream lzoIS; | ||
|
||
public LzoCompressorInputStream(final InputStream in) throws IOException { | ||
this.lzoIS = new LzoCodec().createInputStream(countingStream = new CountingInputStream(in)); | ||
} | ||
|
||
@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); | ||
count(ret); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return lzoIS.toString(); | ||
} | ||
|
||
@Override | ||
public void reset() throws IOException { | ||
lzoIS.reset(); | ||
} | ||
|
||
@Override | ||
public long getCompressedCount() { | ||
return countingStream.getBytesRead(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
sdks/java/core/src/main/java/org/apache/beam/sdk/util/LzoCompressorOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.OutputStream; | ||
import org.apache.commons.compress.compressors.CompressorOutputStream; | ||
|
||
public class LzoCompressorOutputStream extends CompressorOutputStream { | ||
|
||
private final OutputStream lzoOS; | ||
|
||
public LzoCompressorOutputStream(final OutputStream outStream) throws IOException { | ||
this.lzoOS = new LzoCodec().createOutputStream(outStream); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
lzoOS.close(); | ||
} | ||
|
||
@Override | ||
public void write(final int b) throws IOException { | ||
lzoOS.write(b); | ||
} | ||
|
||
@Override | ||
public void write(final byte[] b) throws IOException { | ||
lzoOS.write(b); | ||
} | ||
|
||
@Override | ||
public void write(final byte[] buf, final int off, final int len) throws IOException { | ||
lzoOS.write(buf, off, len); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return lzoOS.toString(); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
lzoOS.flush(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
sdks/java/core/src/main/java/org/apache/beam/sdk/util/LzopCompressorInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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.LzopCodec; | ||
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; | ||
|
||
public class LzopCompressorInputStream extends CompressorInputStream | ||
implements InputStreamStatistics { | ||
|
||
private final CountingInputStream countingStream; | ||
private final InputStream lzoIS; | ||
|
||
public LzopCompressorInputStream(final InputStream in) throws IOException { | ||
this.lzoIS = new LzopCodec().createInputStream(countingStream = new CountingInputStream(in)); | ||
} | ||
|
||
@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); | ||
count(ret); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return lzoIS.toString(); | ||
} | ||
|
||
@Override | ||
public void reset() throws IOException { | ||
lzoIS.reset(); | ||
} | ||
|
||
@Override | ||
public long getCompressedCount() { | ||
return countingStream.getBytesRead(); | ||
} | ||
} |
Oops, something went wrong.