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.kaaproject.kaa.server.control.service.sdk.ObjCSdkGenerator.java
@Override public FileData generateSdk(String buildVersion, List<BootstrapNodeInfo> bootstrapNodes, SdkProfileDto sdkProperties, String profileSchemaBody, String notificationSchemaBody, String configurationProtocolSchemaBody, String configurationBaseSchemaBody, byte[] defaultConfigurationData, List<EventFamilyMetadata> eventFamilies, String logSchemaBody) throws Exception { final String sdkToken = sdkProperties.getToken(); final String defaultVerifierToken = sdkProperties.getDefaultVerifierToken(); String sdkTemplateLocation = System.getProperty("server_home_dir") + "/" + SDK_TEMPLATE_DIR + SDK_PREFIX + buildVersion + ".tar.gz"; LOG.debug("Lookup Objective C SDK template: {}", sdkTemplateLocation); CompressorStreamFactory csf = new CompressorStreamFactory(); ArchiveStreamFactory asf = new ArchiveStreamFactory(); CompressorInputStream cis = csf.createCompressorInputStream(CompressorStreamFactory.GZIP, new FileInputStream(sdkTemplateLocation)); final ArchiveInputStream templateArchive = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, cis); ByteArrayOutputStream sdkOutput = new ByteArrayOutputStream(); CompressorOutputStream cos = csf.createCompressorOutputStream(CompressorStreamFactory.GZIP, sdkOutput); ArchiveOutputStream sdkFile = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, cos); Map<String, TarEntryData> replacementData = new HashMap<>(); List<TarEntryData> objcSources = new ArrayList<>(); if (StringUtils.isNotBlank(profileSchemaBody)) { LOG.debug("Generating profile schema"); Schema profileSchema = new Schema.Parser().parse(profileSchemaBody); String profileClassName = PROFILE_NAMESPACE + profileSchema.getName(); String profileCommonHeader = readResource(PROFILE_TEMPLATE_DIR + PROFILE_COMMON + _H + TEMPLATE_SUFFIX) .replaceAll(PROFILE_CLASS_VAR, profileClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(profileCommonHeader, KAA_ROOT + PROFILE_DIR + PROFILE_COMMON + _H)); String profileCommonSource = readResource(PROFILE_TEMPLATE_DIR + PROFILE_COMMON + _M + TEMPLATE_SUFFIX) .replaceAll(PROFILE_CLASS_VAR, profileClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(profileCommonSource, KAA_ROOT + PROFILE_DIR + PROFILE_COMMON + _M)); objcSources.addAll(generateSourcesFromSchema(profileSchema, PROFILE_GEN, PROFILE_NAMESPACE)); }//w w w.j a v a 2 s . co m String logClassName = ""; if (StringUtils.isNotBlank(logSchemaBody)) { LOG.debug("Generating log schema"); Schema logSchema = new Schema.Parser().parse(logSchemaBody); logClassName = LOGGING_NAMESPACE + logSchema.getName(); String logRecordHeader = readResource(LOG_TEMPLATE_DIR + LOG_RECORD + _H + TEMPLATE_SUFFIX) .replaceAll(LOG_RECORD_CLASS_VAR, logClassName); objcSources .add(CommonSdkUtil.tarEntryForSources(logRecordHeader, KAA_ROOT + LOG_DIR + LOG_RECORD + _H)); String logRecordSource = readResource(LOG_TEMPLATE_DIR + LOG_RECORD + _M + TEMPLATE_SUFFIX) .replaceAll(LOG_RECORD_CLASS_VAR, logClassName); objcSources .add(CommonSdkUtil.tarEntryForSources(logRecordSource, KAA_ROOT + LOG_DIR + LOG_RECORD + _M)); String logCollector = readResource(LOG_TEMPLATE_DIR + LOG_COLLECTOR_INTERFACE + TEMPLATE_SUFFIX) .replaceAll(LOG_RECORD_CLASS_VAR, logClassName); objcSources.add( CommonSdkUtil.tarEntryForSources(logCollector, KAA_ROOT + LOG_DIR + LOG_COLLECTOR_INTERFACE)); String logCollectorImplHeader = readResource( LOG_TEMPLATE_DIR + LOG_COLLECTOR_SOURCE + _H + TEMPLATE_SUFFIX).replaceAll(LOG_RECORD_CLASS_VAR, logClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(logCollectorImplHeader, KAA_ROOT + LOG_DIR + LOG_COLLECTOR_SOURCE + _H)); String logCollectorImplSource = readResource( LOG_TEMPLATE_DIR + LOG_COLLECTOR_SOURCE + _M + TEMPLATE_SUFFIX).replaceAll(LOG_RECORD_CLASS_VAR, logClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(logCollectorImplSource, KAA_ROOT + LOG_DIR + LOG_COLLECTOR_SOURCE + _M)); objcSources.addAll(generateSourcesFromSchema(logSchema, LOG_GEN, LOGGING_NAMESPACE)); } String configurationClassName = ""; if (StringUtils.isNotBlank(configurationBaseSchemaBody)) { LOG.debug("Generating configuration schema"); Schema configurationSchema = new Schema.Parser().parse(configurationBaseSchemaBody); configurationClassName = CONFIGURATION_NAMESPACE + configurationSchema.getName(); String configurationCommon = readResource( CONFIGURATION_TEMPLATE_DIR + CONFIGURATION_COMMON + TEMPLATE_SUFFIX) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(configurationCommon, KAA_ROOT + CONFIGURATION_DIR + CONFIGURATION_COMMON)); String cfManagerImplHeader = readResource( CONFIGURATION_TEMPLATE_DIR + CONFIGURATION_MANAGER_IMPL + _H + TEMPLATE_SUFFIX) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(cfManagerImplHeader, KAA_ROOT + CONFIGURATION_DIR + CONFIGURATION_MANAGER_IMPL + _H)); String cfManagerImplSource = readResource( CONFIGURATION_TEMPLATE_DIR + CONFIGURATION_MANAGER_IMPL + _M + TEMPLATE_SUFFIX) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(cfManagerImplSource, KAA_ROOT + CONFIGURATION_DIR + CONFIGURATION_MANAGER_IMPL + _M)); String cfDeserializerHeader = readResource( CONFIGURATION_TEMPLATE_DIR + CONFIGURATION_DESERIALIZER + _H + TEMPLATE_SUFFIX) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(cfDeserializerHeader, KAA_ROOT + CONFIGURATION_DIR + CONFIGURATION_DESERIALIZER + _H)); String cfDeserializerSource = readResource( CONFIGURATION_TEMPLATE_DIR + CONFIGURATION_DESERIALIZER + _M + TEMPLATE_SUFFIX) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(cfDeserializerSource, KAA_ROOT + CONFIGURATION_DIR + CONFIGURATION_DESERIALIZER + _M)); objcSources.addAll( generateSourcesFromSchema(configurationSchema, CONFIGURATION_GEN, CONFIGURATION_NAMESPACE)); } if (StringUtils.isNotBlank(notificationSchemaBody)) { LOG.debug("Generating notification schema"); Schema notificationSchema = new Schema.Parser().parse(notificationSchemaBody); String notificationClassName = NOTIFICATION_NAMESPACE + notificationSchema.getName(); String nfCommonHeader = readResource( NOTIFICATION_TEMPLATE_DIR + NOTIFICATION_COMMON + _H + TEMPLATE_SUFFIX) .replaceAll(NOTIFICATION_CLASS_VAR, notificationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(nfCommonHeader, KAA_ROOT + NOTIFICATION_DIR + NOTIFICATION_COMMON + _H)); String nfCommonSource = readResource( NOTIFICATION_TEMPLATE_DIR + NOTIFICATION_COMMON + _M + TEMPLATE_SUFFIX) .replaceAll(NOTIFICATION_CLASS_VAR, notificationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(nfCommonSource, KAA_ROOT + NOTIFICATION_DIR + NOTIFICATION_COMMON + _M)); objcSources.addAll( generateSourcesFromSchema(notificationSchema, NOTIFICATION_GEN, NOTIFICATION_NAMESPACE)); } if (eventFamilies != null && !eventFamilies.isEmpty()) { objcSources.addAll(ObjCEventClassesGenerator.generateEventSources(eventFamilies)); } String kaaClient = readResource(SDK_TEMPLATE_DIR + KAA_CLIENT + TEMPLATE_SUFFIX) .replaceAll(LOG_RECORD_CLASS_VAR, logClassName) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(kaaClient, KAA_ROOT + KAA_CLIENT)); String baseKaaClientHeader = readResource(SDK_TEMPLATE_DIR + BASE_KAA_CLIENT + _H + TEMPLATE_SUFFIX) .replaceAll(LOG_RECORD_CLASS_VAR, logClassName) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(baseKaaClientHeader, KAA_ROOT + BASE_KAA_CLIENT + _H)); String baseKaaClientSource = readResource(SDK_TEMPLATE_DIR + BASE_KAA_CLIENT + _M + TEMPLATE_SUFFIX) .replaceAll(LOG_RECORD_CLASS_VAR, logClassName) .replaceAll(CONFIGURATION_CLASS_VAR, configurationClassName); objcSources.add(CommonSdkUtil.tarEntryForSources(baseKaaClientSource, KAA_ROOT + BASE_KAA_CLIENT + _M)); String tokenVerifier = defaultVerifierToken == null ? "nil" : "@\"" + defaultVerifierToken + "\""; String tokenVerifierSource = readResource(EVENT_TEMPLATE_DIR + USER_VERIFIER_CONSTANTS + TEMPLATE_SUFFIX) .replaceAll(DEFAULT_USER_VERIFIER_TOKEN_VAR, tokenVerifier); objcSources.add(CommonSdkUtil.tarEntryForSources(tokenVerifierSource, KAA_ROOT + EVENT_DIR + USER_VERIFIER_CONSTANTS)); String kaaDefaultsTemplate = readResource(SDK_TEMPLATE_DIR + KAA_DEFAULTS + TEMPLATE_SUFFIX); objcSources.add(generateKaaDefaults(kaaDefaultsTemplate, bootstrapNodes, sdkToken, configurationProtocolSchemaBody, defaultConfigurationData, sdkProperties)); for (TarEntryData entryData : objcSources) { replacementData.put(entryData.getEntry().getName(), entryData); } ArchiveEntry archiveEntry; while ((archiveEntry = templateArchive.getNextEntry()) != null) { if (!archiveEntry.isDirectory()) { if (replacementData.containsKey(archiveEntry.getName())) { TarEntryData entryData = replacementData.remove(archiveEntry.getName()); sdkFile.putArchiveEntry(entryData.getEntry()); sdkFile.write(entryData.getData()); } else { sdkFile.putArchiveEntry(archiveEntry); IOUtils.copy(templateArchive, sdkFile); } } else { sdkFile.putArchiveEntry(archiveEntry); } sdkFile.closeArchiveEntry(); } templateArchive.close(); for (String entryName : replacementData.keySet()) { TarEntryData entryData = replacementData.get(entryName); sdkFile.putArchiveEntry(entryData.getEntry()); sdkFile.write(entryData.getData()); sdkFile.closeArchiveEntry(); } sdkFile.finish(); sdkFile.close(); String sdkFileName = SDK_PREFIX + sdkProperties.getToken() + ".tar.gz"; byte[] sdkData = sdkOutput.toByteArray(); FileData sdk = new FileData(); sdk.setFileName(sdkFileName); sdk.setFileData(sdkData); return sdk; }
From source file:org.moe.cli.manager.PrebuildCocoaPodsManager.java
public IExecutor processCocoapods(String source, SpecObject spec, String packageName, String[] javaSource, String outputJar) throws IOException, CompressorException, ArchiveException, InvalidParameterSpecException, InterruptedException, URISyntaxException, UnsupportedTypeException { File tmpFolder = NatJFileUtils.getNewTempDirectory(); File download = new File(tmpFolder, "download/"); if (!download.exists()) { download.mkdirs();// ww w. ja v a 2 s . com } int nameIdx = source.lastIndexOf("/"); File outFile = new File(download, source.substring(nameIdx + 1)); GrabUtils.download(new URI(source), outFile); int extIdx = outFile.getName().lastIndexOf("."); String folderUnzip = outFile.getName().substring(0, extIdx); File destination = new File(download, folderUnzip); if (!destination.exists()) { destination.mkdirs(); } String type = spec.getSource().get("type"); if (outFile.getName().endsWith(".zip") || (type != null && type.equals("zip"))) { ZipFile apachZip = new ZipFile(outFile); ArchiveUtils.unzipArchive(apachZip, destination); } else if (outFile.getName().endsWith("tar.bzip2") || outFile.getName().endsWith("tar.gz") || outFile.getName().endsWith("tar.bz2") || type.equals("tgz")) { InputStream inputC = null; int extArchIdx = outFile.getName().lastIndexOf("."); String ext = outFile.getName().substring(extArchIdx + 1); if (ext.equals("tar")) { inputC = new FileInputStream(outFile); } else if (ext.equals("bzip2") || ext.equals("gz") || ext.equals("bz2")) { InputStream fin = new FileInputStream(outFile); String compressorType = null; if (ext.equals("bzip2") || ext.equals("bz2")) { compressorType = CompressorStreamFactory.BZIP2; } else if (ext.equals("gz") || type.equals("tgz")) { compressorType = CompressorStreamFactory.GZIP; } inputC = new CompressorStreamFactory().createCompressorInputStream(compressorType, fin); } else { throw new InvalidParameterException("Unsupported archive type"); } ArchiveInputStream input = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, inputC); ArchiveUtils.untarArchive(input, destination); } //update destination for git repo if (spec.getSource().containsKey("git")) { String git = spec.getSource().get("git"); String tag = spec.getSource().get("tag"); int gitNameIdx = git.lastIndexOf("/"); String gitName = git.substring(gitNameIdx + 1); if (gitName.endsWith(".git")) { gitName = gitName.substring(0, gitName.length() - 4); } if (!Character.isDigit(tag.charAt(0)) && Character.isDigit(tag.charAt(1))) { tag = tag.substring(1); } String zipSubfolder = String.format("%s-%s", gitName, tag); destination = new File(destination, zipSubfolder); } List<String> commandList = spec.getPreparedCommands(); for (String command : commandList) { if (command != null && !command.isEmpty()) { executePrepareCommands(destination, command); } } IExecutor executor = null; //find all bundles Set<String> bundleContent = new HashSet<String>(); List<String> resources = spec.getResources(); if (resources != null && resources.size() > 0) { for (String bundle : resources) { Set<String> bundleWildCard = getBundleResources(bundle, destination); bundleContent.addAll(bundleWildCard); } } String[] bundleRes = bundleContent.toArray(new String[0]); //get additional linker flags String ldFlags = spec.getLdFlags(); //create Set<String> headersContent = new HashSet<String>(); List<String> headerList = spec.getSourceFiles(); if (headerList != null && headerList.size() > 0) { for (String header : headerList) { int recursivIdx = header.indexOf("**"); if (recursivIdx >= 0) { File headerFile = new File(destination, header.substring(0, recursivIdx)); headersContent.add(headerFile.getPath()); } else { Set<String> bundleWildCard = getBundleResources(header, destination); headersContent.addAll(bundleWildCard); } } } if (spec.getVendoredFrameworks() != null && spec.getVendoredFrameworks().size() > 0) { List<File> frameworkList = new ArrayList<>(); Set<String> frameworkContent = new HashSet<String>(); for (String vFramework : spec.getVendoredFrameworks()) { Set<String> frName = getBundleResources(vFramework, destination); if (frName.size() != 1) throw new RuntimeException( "Something wrong with this code. Refactor it! And the same with libraries"); File frameworkFile = new File(frName.toArray(new String[0])[0]); if (frameworkFile.exists()) { frameworkList.add(frameworkFile); frameworkContent.add(frameworkFile.getPath()); int frameworkNameIdx = frameworkFile.getName().lastIndexOf("."); if (frameworkNameIdx >= 0) { ldFlags = ldFlags + "-framework " + frameworkFile.getName().substring(0, frameworkNameIdx) + ";"; } } } if (headersContent.isEmpty()) { for (File framework : frameworkList) { File headerFile = new File(framework, "Headers"); headersContent.add(headerFile.getPath()); } } executor = new ThirdPartyFrameworkLinkExecutor(packageName, frameworkContent.toArray(new String[0]), javaSource, headersContent.toArray(new String[0]), bundleRes, outputJar, ldFlags); } else if (spec.getVendoredLibraries() != null && spec.getVendoredLibraries().size() > 0) { Set<String> libContent = new HashSet<String>(); for (String lib : spec.getVendoredLibraries()) { Set<String> libName = getBundleResources(lib, destination); if (libName.size() != 1) throw new RuntimeException( "Something wrong with this code. Refactor it! And the same with libraries"); File library = new File(libName.toArray(new String[0])[0]); if (library.exists()) { libContent.add(library.getPath()); int libNameIdx = library.getName().lastIndexOf("."); if (libNameIdx >= 0) { String libShortName = library.getName().substring(0, libNameIdx); ldFlags = ldFlags + "-l" + (libShortName.startsWith("lib") ? libShortName.substring(3) : libShortName) + ";"; } } } executor = new ThirdPartyLibraryLinkExecutor(packageName, libContent.toArray(new String[0]), javaSource, headersContent.toArray(new String[0]), bundleRes, outputJar, ldFlags); } return executor; }
From source file:org.springframework.cloud.stream.app.tensorflow.util.ModelExtractor.java
/** * Detect the Archive and the Compressor from the file extension * * @param fileName File name with extension * @return Returns a tuple of the detected (Archive, Compressor). Null stands for not available archive or detector. * The (null, null) response stands for no Archive or Compressor discovered. */// w w w . j a v a2s .co m private String[] detectArchiveAndCompressor(String fileName) { String normalizedFileName = fileName.trim().toLowerCase(); if (normalizedFileName.endsWith(".tar.gz") || normalizedFileName.endsWith(".tgz") || normalizedFileName.endsWith(".taz")) { return new String[] { ArchiveStreamFactory.TAR, CompressorStreamFactory.GZIP }; } else if (normalizedFileName.endsWith(".tar.bz2") || normalizedFileName.endsWith(".tbz2") || normalizedFileName.endsWith(".tbz")) { return new String[] { ArchiveStreamFactory.TAR, CompressorStreamFactory.BZIP2 }; } else if (normalizedFileName.endsWith(".cpgz")) { return new String[] { ArchiveStreamFactory.CPIO, CompressorStreamFactory.GZIP }; } else if (hasArchive(normalizedFileName)) { return new String[] { findArchive(normalizedFileName).get(), null }; } else if (hasCompressor(normalizedFileName)) { return new String[] { null, findCompressor(normalizedFileName).get() }; } else if (normalizedFileName.endsWith(".gzip")) { return new String[] { null, CompressorStreamFactory.GZIP }; } else if (normalizedFileName.endsWith(".bz2") || normalizedFileName.endsWith(".bz")) { return new String[] { null, CompressorStreamFactory.BZIP2 }; } // No archived/compressed return new String[] { null, null }; }
From source file:rv.comm.rcssserver.TarBz2ZipUtil.java
/** * Creates the reader used for sequential reading * //from w w w . j a va 2s .c o m * @return the reader used for sequential reading * @throws FileNotFoundException * if the logsrc is not found */ public static BufferedReader createBufferedReader(File file) throws FileNotFoundException { Reader reader = null; if (isTarBZ2Ending(file)) { reader = getTarBZ2InputStream(file); } else if (isBZ2Ending(file)) { reader = getCompressedInputStream(file, CompressorStreamFactory.BZIP2); } else if (isGZipEnding(file)) { reader = getCompressedInputStream(file, CompressorStreamFactory.GZIP); } else if (isZIPEnding(file)) { reader = getZipStream(file); } else { reader = new FileReader(file); } return new BufferedReader(reader); }
From source file:rv.comm.rcssserver.TarBz2ZipUtil.java
/** * Creates the writer as zip, bz2 or unpacked stream * //from www . j av a2s. c om * @return the writer used for sequential reading * @throws IOException */ public static PrintWriter createPrintWriter(File file) throws IOException { Writer writer = null; if (isTarBZ2Ending(file)) { // TODO: add support for tar writing writer = getCompressingWriter(file, CompressorStreamFactory.BZIP2); } else if (isBZ2Ending(file)) { writer = getCompressingWriter(file, CompressorStreamFactory.BZIP2); } else if (isGZipEnding(file)) { writer = getCompressingWriter(file, CompressorStreamFactory.GZIP); } else { writer = new FileWriter(file); } return new PrintWriter(new BufferedWriter(writer)); }