List of usage examples for org.apache.commons.compress.compressors CompressorStreamFactory GZIP
String GZIP
To view the source code for org.apache.commons.compress.compressors CompressorStreamFactory GZIP.
Click Source Link
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssembler.java
private void validateCompressionFormat() { // convert gzip to gz if (compressionFormat.equals("gzip")) { compressionFormat = CompressorStreamFactory.GZIP; }/* ww w . j ava 2 s . c om*/ if (!compressionFormat.equals(CompressorStreamFactory.BZIP2) && !compressionFormat.equals(CompressorStreamFactory.GZIP) && !compressionFormat.equals(CompressorStreamFactory.PACK200) && !compressionFormat.equals("none")) { throw new PackageToolException(PackagingToolReturnInfo.PKG_ASSEMBLER_INVALID_PARAMS, String.format( "Specified compression format %s is not supported. The supported compression " + "formats are: %s (or %s), %s, %s, none.", compressionFormat, CompressorStreamFactory.GZIP, "gzip", CompressorStreamFactory.BZIP2, CompressorStreamFactory.PACK200)); } }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
@Before public void setUp() throws URISyntaxException { //Set up parameters packageName = "WillardDoodle"; packageLocationName = packageLocation.getAbsolutePath(); packageStagingLocationName = packageStagingLocation.getAbsolutePath(); bagItProfileId = "http://dataconservancy.org/formats/data-conservancy-pkg-0.9"; contactName = "Willy Bean"; contactEmail = "Willy.Bean@Bushs.com"; contactPhone = "0000000000"; checksumAlg = "md5"; contentLocation = this.getClass().getResource("/TestContent/").getPath(); contentLocationFile = new File(contentLocation); contentLocationURI = contentLocationFile.toURI(); PackageGenerationParameters params = new PackageGenerationParameters(); setupCommonPackageParams(params);//from www.j a va2s.c om params.addParam(GeneralParameterNames.CHECKSUM_ALGORITHMS, checksumAlg); params.addParam(GeneralParameterNames.COMPRESSION_FORMAT, CompressorStreamFactory.GZIP); //Set up package assembler underTest = new BagItPackageAssembler(); underTest.init(params); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
/** * Test assembling a bag which contain a data file and a metadata file. * @throws IOException// w w w . j a va 2s .c o m */ private void testAssembleBag_TAR_GZIP(String dataFileName) throws IOException, CompressorException, ArchiveException { PackageGenerationParameters params = new PackageGenerationParameters(); setupCommonPackageParams(params); params.addParam(GeneralParameterNames.ARCHIVING_FORMAT, ArchiveStreamFactory.TAR); params.addParam(GeneralParameterNames.COMPRESSION_FORMAT, CompressorStreamFactory.GZIP); params.addParam(GeneralParameterNames.CHECKSUM_ALGORITHMS, checksumAlg); params.addParam(GeneralParameterNames.CHECKSUM_ALGORITHMS, "sha1"); underTest = new BagItPackageAssembler(); underTest.init(params); //Reserve a URI for data file String filePath = "myProject/" + dataFileName; URI result = underTest.reserveResource(filePath, PackageResourceType.DATA); String expectedURI = "file:///" + packageName + "/" + "data" + "/" + filePath; log.debug("URI expected: " + expectedURI); log.debug("URI result: " + result.toString()); assertTrue(expectedURI.equals(result.toString())); //Put content into the space specified by the URI String fileContent = "This is the data file. data data data data data data data data data data data data."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); //Reserve a URI for metadata file filePath = "metadataFile.txt"; result = underTest.reserveResource(filePath, PackageResourceType.METADATA); expectedURI = "file:///" + packageName + "/" + filePath; assertTrue(expectedURI.equals(result.toString())); //Put content into the space specified by the URI fileContent = "This is the metadata file. metadata metadata metadata metadata metadata metadata metadata ."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, cis); Set<String> files = new HashSet<String>(); ArchiveEntry entry = ais.getNextEntry(); while (entry != null) { files.add(entry.getName().replace("\\", "/")); entry = ais.getNextEntry(); } //Make sure that the packageName is set properly (packageName + contentype extension) String expectedPackageName = packageName.concat(".tar").concat(".gz"); Assert.assertEquals(expectedPackageName, pkg.getPackageName()); // There should be 10 files: the 2 files above, bagit.txt, bag-info.txt // directories data and data/myProject, 2 manifest files and 2 tag-manifest files assertEquals(10, files.size()); // make sure that expected files are in there String pathSep = "/"; String bagFilePath = packageName + pathSep; assertTrue(files.contains(bagFilePath + "bagit.txt")); assertTrue(files.contains(bagFilePath + "bag-info.txt")); assertTrue(files.contains(bagFilePath + "metadataFile.txt")); assertTrue(files.contains(bagFilePath + "data" + pathSep)); assertTrue(files.contains(bagFilePath + "data" + pathSep + "myProject" + pathSep)); assertTrue(files.contains(bagFilePath + "data" + pathSep + "myProject" + pathSep + dataFileName)); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
/** * Test that the bag-info.txt file contains the parameter information passed in, including * parameters passed in after the initialization. * * Note that the package being generated in this case is empty, so the bag size and payload * oxum values will be 0.//from w w w .j av a2 s . co m * @throws CompressorException * @throws ArchiveException * @throws IOException */ @Test public void testBagItInfoFile() throws CompressorException, ArchiveException, IOException { final String paramName = "TEST_PARAMETER"; final String paramValue = "test parameter"; underTest.addParameter(paramName, paramValue); Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); TarArchiveInputStream ais = (TarArchiveInputStream) (new ArchiveStreamFactory() .createArchiveInputStream(ArchiveStreamFactory.TAR, cis)); String bagInfo = ""; TarArchiveEntry entry = ais.getNextTarEntry(); while (entry != null) { if (entry.getName().contains("bag-info.txt")) { byte[] content = new byte[(int) entry.getSize()]; ais.read(content, 0, (int) entry.getSize()); bagInfo = new String(content); break; } entry = ais.getNextTarEntry(); } // Test that expected initial parameters are present String expected = GeneralParameterNames.PACKAGE_NAME + ": " + packageName; assertTrue("Expected to find: " + expected, bagInfo.contains(expected)); // These two values should be 0 since there is nothing in the test package this time. expected = BagItParameterNames.BAG_SIZE + ": 0"; assertTrue("Expected to find: " + expected, bagInfo.contains(expected)); expected = BagItParameterNames.PAYLOAD_OXUM + ": 0"; assertTrue("Expected to find: " + expected, bagInfo.contains(expected)); // Test the post-init parameter expected = paramName + ": " + paramValue; assertTrue("Expected to find: " + expected, bagInfo.contains(expected)); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
/** * Test that the assembler includes the proper manifest file (and no other manifest files) * @throws IOException//from w w w .ja v a 2 s . c o m */ @Test public void testSingleChecksum() throws IOException, CompressorException, ArchiveException { // The default setup only uses md5 checksum, so we'll stick with that one //Reserve a URI for data file and put it in package String filePath = "myProject/dataFile.txt"; URI result = underTest.reserveResource(filePath, PackageResourceType.DATA); String fileContent = "This is the data file. data data data data data data data data data data data data."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); //Reserve a URI for metadata file and put it in package filePath = "metadataFile.txt"; result = underTest.reserveResource(filePath, PackageResourceType.METADATA); fileContent = "This is the metadata file. metadata metadata metadata metadata metadata metadata metadata ."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, cis); Set<String> files = new HashSet<String>(); ArchiveEntry entry = ais.getNextEntry(); while (entry != null) { files.add(entry.getName()); entry = ais.getNextEntry(); } // make sure that expected files are in there String bagFilePath = packageName + "/"; assertTrue(files.contains(bagFilePath + "manifest-md5.txt")); assertTrue(files.contains(bagFilePath + "tagmanifest-md5.txt")); assertFalse(files.contains(bagFilePath + "manifest-sha1.txt")); assertFalse(files.contains(bagFilePath + "tagmanifest-sha1.txt")); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
/** * Test that the assembler generates both manifest files one for sha1 and one for md5 * @throws IOException/*w w w . j a v a2 s . c om*/ */ @Test public void testMultipleChecksum() throws IOException, CompressorException, ArchiveException { PackageGenerationParameters params = new PackageGenerationParameters(); setupCommonPackageParams(params); params.addParam(GeneralParameterNames.ARCHIVING_FORMAT, ArchiveStreamFactory.TAR); params.addParam(GeneralParameterNames.COMPRESSION_FORMAT, CompressorStreamFactory.GZIP); params.addParam(GeneralParameterNames.CHECKSUM_ALGORITHMS, checksumAlg); params.addParam(GeneralParameterNames.CHECKSUM_ALGORITHMS, "sha1"); underTest = new BagItPackageAssembler(); underTest.init(params); //Reserve a URI for data file and put it in package String filePath = "myProject/dataFile.txt"; URI result = underTest.reserveResource(filePath, PackageResourceType.DATA); String fileContent = "This is the data file. data data data data data data data data data data data data."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); //Reserve a URI for metadata file and put it in package filePath = "metadataFile.txt"; result = underTest.reserveResource(filePath, PackageResourceType.METADATA); fileContent = "This is the metadata file. metadata metadata metadata metadata metadata metadata metadata ."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, cis); Set<String> files = new HashSet<String>(); ArchiveEntry entry = ais.getNextEntry(); while (entry != null) { files.add(entry.getName()); entry = ais.getNextEntry(); } // make sure that expected files are in there String bagFilePath = packageName + "/"; assertTrue(files.contains(bagFilePath + "manifest-md5.txt")); assertTrue(files.contains(bagFilePath + "tagmanifest-md5.txt")); assertTrue(files.contains(bagFilePath + "manifest-sha1.txt")); assertTrue(files.contains(bagFilePath + "tagmanifest-sha1.txt")); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
/** * Test that the assembler includes a manifest file for the default checksum * @throws IOException// ww w . java 2s . c om */ @Test public void testDefaultChecksum() throws IOException, CompressorException, ArchiveException { PackageGenerationParameters params = new PackageGenerationParameters(); setupCommonPackageParams(params); params.addParam(GeneralParameterNames.ARCHIVING_FORMAT, ArchiveStreamFactory.TAR); params.addParam(GeneralParameterNames.COMPRESSION_FORMAT, CompressorStreamFactory.GZIP); // No checksum parameter is given, so md5 should be used by default underTest = new BagItPackageAssembler(); underTest.init(params); //Reserve a URI for data file and put it in package String filePath = "myProject/dataFile.txt"; URI result = underTest.reserveResource(filePath, PackageResourceType.DATA); String fileContent = "This is the data file. data data data data data data data data data data data data."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); //Reserve a URI for metadata file and put it in package filePath = "metadataFile.txt"; result = underTest.reserveResource(filePath, PackageResourceType.METADATA); fileContent = "This is the metadata file. metadata metadata metadata metadata metadata metadata metadata ."; underTest.putResource(result, new ByteArrayInputStream(fileContent.getBytes())); Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, cis); Set<String> files = new HashSet<String>(); ArchiveEntry entry = ais.getNextEntry(); while (entry != null) { files.add(entry.getName()); entry = ais.getNextEntry(); } // make sure that expected files are in there String bagFilePath = packageName + "/"; assertTrue(files.contains(bagFilePath + "manifest-md5.txt")); assertTrue(files.contains(bagFilePath + "tagmanifest-md5.txt")); assertFalse(files.contains(bagFilePath + "manifest-sha1.txt")); assertFalse(files.contains(bagFilePath + "tagmanifest-sha1.txt")); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
@Test public void testValidArchiveValidCompressionAssemblesAsSpecified() throws CompressorException, ArchiveException, IOException { PackageGenerationParameters params = new PackageGenerationParameters(); setupCommonPackageParams(params);/* ww w. jav a2 s .c o m*/ params.addParam(GeneralParameterNames.ARCHIVING_FORMAT, ArchiveStreamFactory.TAR); params.addParam(GeneralParameterNames.COMPRESSION_FORMAT, CompressorStreamFactory.GZIP); underTest = new BagItPackageAssembler(); underTest.init(params); // no data files need to be added, as the bag-it files will be sufficient to test Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, cis); assertNotNull(ais.getNextEntry()); }
From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java
@Test public void testNoArchiveValidCompressionAssemblesCompressedTar() throws CompressorException, ArchiveException, IOException { PackageGenerationParameters params = new PackageGenerationParameters(); setupCommonPackageParams(params);/* www. j a va2 s. c o m*/ params.addParam(GeneralParameterNames.COMPRESSION_FORMAT, CompressorStreamFactory.GZIP); underTest = new BagItPackageAssembler(); underTest.init(params); // no data files need to be added, as the bag-it files will be sufficient to test Package pkg = underTest.assemblePackage(); CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, pkg.serialize()); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, cis); assertNotNull(ais.getNextEntry()); }
From source file:org.deventropy.shared.utils.DirectoryArchiverUtil.java
/** * Create a GZipped tar archive with all the contents of the directory. Optionally push the contents down a * directory level or two./*from www.j a v a2 s.c o m*/ * * @param archiveFile The final archive file location. The file location must be writable. * @param srcDirectory The source directory. * @param rootPathPrefix The root prefix. Multiple directory parts should be separated by <code>/</code>. * @throws IOException Exception reading the source directory or writing to the destination file. */ public static void createGZippedTarArchiveOfDirectory(final String archiveFile, final File srcDirectory, final String rootPathPrefix) throws IOException { createArchiveOfDirectory(archiveFile, srcDirectory, rootPathPrefix, ArchiveStreamFactory.TAR, null, new TarArchiverCreateProcessor(CompressorStreamFactory.GZIP)); }