use of java.util.zip.ZipException in project bnd by bndtools.
the class Domain method domain.
public static Domain domain(File file) throws IOException {
if (file.getName().endsWith(".mf")) {
try (InputStream in = IO.stream(file)) {
Manifest m = new Manifest(in);
return domain(m);
}
}
if (file.getName().endsWith(".properties") || file.getName().endsWith(".bnd")) {
Processor p = new Processor();
p.setProperties(file);
return domain(p);
}
if (file.getName().endsWith(".pom")) {
try {
PomParser p = new PomParser();
p.setProperties(p.getProperties(file));
return domain(p);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
// default & last. Assume JAR
try (JarInputStream jin = new JarInputStream(IO.stream(file))) {
Manifest m = jin.getManifest();
if (m != null)
return domain(m);
}
try (ZipFile zf = new ZipFile(file)) {
ZipEntry entry = zf.getEntry("META-INF/MANIFEST.MF");
if (entry == null)
return null;
Manifest m = new Manifest(zf.getInputStream(entry));
return domain(m);
} catch (ZipException e) {
return null;
}
}
use of java.util.zip.ZipException in project Payara by payara.
the class AppClientDeployerHelper method copy.
/**
* copy the entryName element from the source abstract archive into
* the target abstract archive
*/
static void copy(ReadableArchive source, WritableArchive target, String entryName) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
is = source.getEntry(entryName);
if (is != null) {
try {
os = target.putNextEntry(entryName);
} catch (ZipException ze) {
// this is a duplicate...
return;
}
ArchivistUtils.copyWithoutClose(is, os);
} else {
// entryName as a prefix.
for (Enumeration e = source.entries(entryName); e.hasMoreElements(); ) {
copy(source, target, (String) e.nextElement());
}
}
} catch (IOException ioe) {
throw ioe;
} finally {
IOException closeEntryIOException = null;
if (os != null) {
try {
target.closeEntry();
} catch (IOException ioe) {
closeEntryIOException = ioe;
}
}
if (is != null) {
is.close();
}
if (closeEntryIOException != null) {
throw closeEntryIOException;
}
}
}
use of java.util.zip.ZipException in project Payara by payara.
the class Assembler method transferFile.
void transferFile(File file, JarOutputStream jos, String entryName) throws IOException {
if (file == null || jos == null || entryName == null) {
return;
}
ZipEntry entry = new ZipEntry(entryName);
try {
jos.putNextEntry(entry);
} catch (ZipException ex) {
return;
}
FileInputStream fin = new FileInputStream(file);
transferContents(fin, jos);
jos.closeEntry();
}
use of java.util.zip.ZipException in project pentaho-platform by pentaho.
the class ZipExportProcessor method exportDirectory.
/**
* @param repositoryDir
* @param outputStream
*/
@Override
public void exportDirectory(RepositoryFile repositoryDir, OutputStream outputStream, String filePath) throws ExportException, IOException {
addToManifest(repositoryDir);
List<RepositoryFile> children = getUnifiedRepository().getChildren(new RepositoryRequest(String.valueOf(repositoryDir.getId()), true, 1, null));
for (RepositoryFile repositoryFile : children) {
// exclude 'etc' folder - datasources and etc.
if (isExportCandidate(repositoryFile.getPath())) {
if (repositoryFile.isFolder()) {
if (outputStream.getClass().isAssignableFrom(ZipOutputStream.class)) {
ZipOutputStream zos = (ZipOutputStream) outputStream;
String zipEntryName = getFixedZipEntryName(repositoryFile, filePath);
ZipEntry entry = new ZipEntry(zipEntryName);
zos.putNextEntry(entry);
}
exportDirectory(repositoryFile, outputStream, filePath);
} else {
try {
exportFile(repositoryFile, outputStream, filePath);
} catch (ZipException e) {
// possible duplicate entry, log it and continue on with the other files in the directory
log.debug(e.getMessage(), e);
}
}
}
}
createLocales(repositoryDir, filePath, repositoryDir.isFolder(), outputStream);
}
use of java.util.zip.ZipException in project knox by apache.
the class UrlRewriteResponse method streamResponse.
@Override
public void streamResponse(InputStream input, OutputStream output) throws IOException {
InputStream inStream;
OutputStream outStream;
boolean isGzip = false;
BufferedInputStream inBuffer = new BufferedInputStream(input);
try {
// Use this way to check whether the input stream is gzip compressed, in case
// the content encoding header is unknown, as it could be unset in inbound response
inBuffer.mark(STREAM_BUFFER_SIZE);
inStream = new GZIPInputStream(inBuffer);
isGzip = true;
} catch (ZipException e) {
inBuffer.reset();
inStream = inBuffer;
} catch (IOException e) {
inBuffer.reset();
inStream = inBuffer;
}
MimeType mimeType = getMimeType();
UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig(rewriter.getConfig(), bodyFilterName, mimeType);
if (filterContentConfig != null) {
String asType = filterContentConfig.asType();
if (asType != null && asType.trim().length() > 0) {
mimeType = MimeTypes.create(asType, getCharacterEncoding());
}
}
InputStream filteredInput = UrlRewriteStreamFilterFactory.create(mimeType, null, inStream, rewriter, this, UrlRewriter.Direction.OUT, filterContentConfig);
outStream = (isGzip) ? new GZIPOutputStream(output) : output;
IOUtils.copyLarge(filteredInput, outStream, new byte[STREAM_BUFFER_SIZE]);
// KNOX-685: outStream.flush();
outStream.close();
}
Aggregations