本文整理匯總了Java中org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream類的典型用法代碼示例。如果您正苦於以下問題:Java GzipCompressorOutputStream類的具體用法?Java GzipCompressorOutputStream怎麽用?Java GzipCompressorOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GzipCompressorOutputStream類屬於org.apache.commons.compress.compressors.gzip包,在下文中一共展示了GzipCompressorOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTarGzipPacker
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
/**
* create TarGzipPacker object
*/
public static TarGzipPacker createTarGzipPacker(String targetDir, Config config) {
// this should be received from config
String archiveFilename = SchedulerContext.jobPackageFileName(config);
Path archiveFile = Paths.get(targetDir + "/" + archiveFilename);
try {
// construct output stream
OutputStream outStream = Files.newOutputStream(archiveFile);
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(outStream);
TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream);
return new TarGzipPacker(archiveFile, tarOutputStream);
} catch (IOException ioe) {
LOG.log(Level.SEVERE, "Archive file can not be created: " + archiveFile, ioe);
return null;
}
}
示例2: createTarGZ
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
public static void createTarGZ(String dirPath, String tarGzPath, boolean deleteTempDir) throws IOException {
try (
OutputStream fOut = new FileOutputStream(new File(tarGzPath));
OutputStream bOut = new BufferedOutputStream(fOut);
OutputStream gzOut = new GzipCompressorOutputStream(bOut);
TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)
)
{
File f = new File(dirPath);
if (f.isDirectory()) {
//pass over all the files in the directory
File[] children = f.listFiles();
if (children != null) {
for (File child : children) {
addFileToTarGz(tOut, child);
}
}
if(deleteTempDir) {
deleteTempFolder(dirPath);
}
} else {
System.out.println("The given directury path is not a directory");
}
}
}
示例3: initialize
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
@Override
public void initialize(UimaContext aContext)
throws ResourceInitializationException
{
super.initialize(aContext);
// some param check
if (!outputFile.getName().endsWith(".tar.gz")) {
throw new ResourceInitializationException(
new IllegalArgumentException("Output file must have .tar.gz extension"));
}
typeSystemWritten = false;
try {
outputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(
new BufferedOutputStream(new FileOutputStream(outputFile))));
}
catch (IOException ex) {
throw new ResourceInitializationException(ex);
}
}
示例4: getOutputStreamForMode
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
/**
* Get a compressing stream for a given compression mode.
*/
private OutputStream getOutputStreamForMode(CompressionMode mode, OutputStream stream)
throws IOException {
switch (mode) {
case GZIP:
return new GzipCompressorOutputStream(stream);
case BZIP2:
return new BZip2CompressorOutputStream(stream);
case ZIP:
return new TestZipOutputStream(stream);
case DEFLATE:
return new DeflateCompressorOutputStream(stream);
default:
throw new RuntimeException("Unexpected compression mode");
}
}
示例5: testOpenNext
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
@Test
public void testOpenNext() throws Exception {
new NonStrictExpectations() {{
task.getFormat(); result = "gzip";
task.getBufferAllocator(); result = new MockBufferAllocator();
}};
provider = new CommonsCompressCompressorProvider(task, fileOutput);
OutputStream out = provider.openNext();
assertTrue("Verify a stream instance.", out instanceof GzipCompressorOutputStream);
provider.close();
new Verifications() {{
fileOutput.nextFile(); times = 1;
}};
}
開發者ID:hata,項目名稱:embulk-encoder-commons-compress,代碼行數:17,代碼來源:TestCommonsCompressCompressorProvider.java
示例6: testCreateCompressorOutputStreamGzip
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
@Test
public void testCreateCompressorOutputStreamGzip() throws Exception {
new NonStrictExpectations() {{
task.getFormat(); result = "gzip";
task.getBufferAllocator(); result = new MockBufferAllocator();
}};
provider = new CommonsCompressCompressorProvider(task, fileOutput);
OutputStream out = provider.createCompressorOutputStream();
assertTrue("Verify a stream instance.", out instanceof GzipCompressorOutputStream);
provider.close();
new Verifications() {{
fileOutput.close(); times = 1;
}};
}
開發者ID:hata,項目名稱:embulk-encoder-commons-compress,代碼行數:17,代碼來源:TestCommonsCompressCompressorProvider.java
示例7: compressTarGzFile
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
public static void compressTarGzFile(
final File temporaryTarGzFile,
final Path pathToCompress,
final BuildListener listener)
throws IOException {
try (final TarArchiveOutputStream tarGzArchiveOutputStream =
new TarArchiveOutputStream(
new BufferedOutputStream(
new GzipCompressorOutputStream(
new FileOutputStream(temporaryTarGzFile))))) {
compressArchive(
pathToCompress,
tarGzArchiveOutputStream,
new ArchiveEntryFactory(CompressionType.TarGz),
CompressionType.TarGz,
listener);
}
}
示例8: createTarGz
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
public static boolean createTarGz(File archive, File... files) {
try (
FileOutputStream fileOutputStream = new FileOutputStream(archive);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
GzipCompressorOutputStream gzipOuputStream =
new GzipCompressorOutputStream(bufferedOutputStream);
TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(gzipOuputStream)
) {
for (File file : files) {
addFileToArchive(archiveOutputStream, file, "");
}
archiveOutputStream.finish();
} catch (IOException ioe) {
LOG.error("Failed to create archive {} file.", archive, ioe);
return false;
}
return true;
}
示例9: openFastGzipParallelWriter
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
/**
* Open a concurrent gzip compressed line writer (fastest compression)
* @param target target location
* @param limit the limit per split
* @param maxWriters the maximum number of writers
* @return parallel writer
*/
public static ParallelSplitWriter<String> openFastGzipParallelWriter(File target, final int limit, final int maxWriters) {
return new ParallelSplitWriter<String>(target, maxWriters) {
@Override
protected Writer<String> newWriter(File path) {
GzipParameters parameters = new GzipParameters();
parameters.setCompressionLevel(Deflater.BEST_SPEED);
parameters.setFilename(path.getName());
try {
return new LineWriter(new GzipCompressorOutputStream(new FileOutputStream(path.getAbsolutePath() + ".gz"), parameters), limit);
} catch (IOException e) {
throw new IOError(e);
}
}
};
}
示例10: tar
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
/**
* Similiar to {@link #tar(FileSystem, Path, Path)} except the source and destination {@link FileSystem} can be different.
*
* @see #tar(FileSystem, Path, Path)
*/
public static void tar(FileSystem sourceFs, FileSystem destFs, Path sourcePath, Path destPath) throws IOException {
try (FSDataOutputStream fsDataOutputStream = destFs.create(destPath);
TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(
new GzipCompressorOutputStream(fsDataOutputStream), ConfigurationKeys.DEFAULT_CHARSET_ENCODING.name())) {
FileStatus fileStatus = sourceFs.getFileStatus(sourcePath);
if (sourceFs.isDirectory(sourcePath)) {
dirToTarArchiveOutputStreamRecursive(fileStatus, sourceFs, Optional.<Path> absent(), tarArchiveOutputStream);
} else {
try (FSDataInputStream fsDataInputStream = sourceFs.open(sourcePath)) {
fileToTarArchiveOutputStream(fileStatus, fsDataInputStream, new Path(sourcePath.getName()),
tarArchiveOutputStream);
}
}
}
}
示例11: toTarGz
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
@Override
public void toTarGz(Collection<Communication> commColl, Path outPath) throws ConcreteException {
try(OutputStream os = Files.newOutputStream(outPath);
BufferedOutputStream bos = new BufferedOutputStream(os);
GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(bos);
TarArchiveOutputStream tos = new TarArchiveOutputStream(gzos);) {
for (Communication c : commColl) {
TarArchiveEntry entry = new TarArchiveEntry(c.getId() + ".concrete");
byte[] cbytes = this.toBytes(c);
entry.setSize(cbytes.length);
tos.putArchiveEntry(entry);
try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) {
IOUtils.copy(bis, tos);
tos.closeArchiveEntry();
}
}
} catch (IOException e) {
throw new ConcreteException(e);
}
}
示例12: gzipFile
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
private static void gzipFile(File file) throws IOException {
if (file == null) {
return;
}
String name = GzipUtils.getCompressedFilename(file.getName());
File dest = new File(file.getParentFile(), name);
try (FileOutputStream os = new FileOutputStream(dest)) {
// read the contents
String contents = FileUtils.readFileToString(file, Charsets.UTF_8);
try (OutputStream gzip = new GzipCompressorOutputStream(os)) {
// write / compress
IOUtils.write(contents, gzip, Charsets.UTF_8);
}
} finally {
file.delete(); // delete the file
}
}
示例13: charsEncodeAndCompress
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
public static byte[] charsEncodeAndCompress(CharSequence v) {
try {
byte[] buffer = Utf8Encoder.encode(v);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GzipCompressorOutputStream cos = new GzipCompressorOutputStream(bos);
cos.write(buffer);
cos.close();
bos.close();
return bos.toByteArray();
}
catch (Exception x) {
}
return null;
}
示例14: compress
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
public void compress(final File rootDir) throws IOException {
boolean deleteIncompleteTarGzFile = false;
final OutputStream fout = castStream(tarGzFile.createOutputStream());
try {
deleteIncompleteTarGzFile = true;
final GzipParameters gzipParameters = new GzipParameters();
gzipParameters.setCompressionLevel(Deflater.BEST_COMPRESSION);
final TarArchiveOutputStream out = new TarArchiveOutputStream(new GzipCompressorOutputStream(new BufferedOutputStream(fout), gzipParameters));
try {
writeTar(out, rootDir, rootDir);
} finally {
out.close();
}
deleteIncompleteTarGzFile = false;
} finally {
fout.close();
if (deleteIncompleteTarGzFile)
tarGzFile.delete();
}
}
示例15: constructNewStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入依賴的package包/類
private void constructNewStream(File outputDir) throws IOException {
String archiveName = new SimpleDateFormat("yyyyMMddhhmm'.tar.gz'")
.format(new Date());
LOG.info("Creating a new gzip archive: " + archiveName);
fileOutput = new FileOutputStream(
new File(outputDir + File.separator + archiveName));
bufOutput = new BufferedOutputStream(fileOutput);
gzipOutput = new GzipCompressorOutputStream(bufOutput);
tarOutput = new TarArchiveOutputStream(gzipOutput);
tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
}