A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
This class is used to represent a ZIP file entry. @version 1.42, 01/02/08 @author David Connelly
This class represents a member of a zip archive. ZipFile and ZipInputStream will give you instances of this class as information about the members in an archive. On the other hand ZipOutputStream needs an instance of this class to create a new member. @author Jochen Hoenicke
Extension that adds better handling of extra fields and provides access to the internal and external file attributes. The extra data is expected to follow the recommendation of the .ZIP File Format Specification created by PKWARE Inc. : the extra byte array consists of a sequence of extra fields eac...
public void writeTo(OutputStream out) throws ServiceException, IOException {
// wrap the output stream in a zipped one
ZipOutputStream zip = new ZipOutputStream(out);
// first create an entry for the kml
ZipEntry entry = new ZipEntry("wms.kml");
zip.putNextEntry(entry);
try {
transformer.transform(mapContext, zip);
zip.closeEntry();
} catch (TransformerException e) {
throw (IOException) new IOException().initCause(e);
}
// write the images
for (int i = 0; i < mapContext.getLayerCount(); i++) {
MapLayer mapLayer = mapContext.getLayer(i);
// create a context for this single layer
WMSMapContext mapContext = new WMSMapContext();
mapContext.addLayer(mapLayer);
mapContext.setRequest(this.mapContext.getRequest());
mapContext.setMapHeight(this.mapContext.getMapHeight());
mapContext.setMapWidth(this.mapContext.getMapWidth());
mapContext.setAreaOfInterest(this.mapContext.getAreaOfInterest());
mapContext.setBgColor(this.mapContext.getBgColor());
mapContext.setBuffer(this.mapContext.getBuffer());
mapContext.setContactInformation(this.mapContext
.getContactInformation());
mapContext.setKeywords(this.mapContext.getKeywords());
mapContext.setAbstract(this.mapContext.getAbstract());
mapContext.setTransparent(true);
// render the map
mapProducer.setMapContext(mapContext);
mapProducer.produceMap();
// write it to the zip stream
entry = new ZipEntry("layer_" + i + ".png");
zip.putNextEntry(entry);
mapProducer.writeTo(zip);
zip.closeEntry();
}
emf.printStackTrace();
}
}
// update target.jar.aspectwerkzc working file
ZipEntry transformedZe = new ZipEntry(ze.getName());
transformedZe.setSize(transformed.length);
CRC32 crc = new CRC32();
crc.update(transformed);
transformedZe.setCrc(crc.getValue());
transformedZe.setMethod(ze.getMethod());
zos.putNextEntry(transformedZe);
zos.write(transformed, 0, transformed.length);
// if AW and genjp
if (genJp && out != null && out.emittedJoinPoints!=null) {
for (int i = 0; i < out.emittedJoinPoints.length; i++) {
EmittedJoinPoint emittedJoinPoint = out.emittedJoinPoints[i];
JoinPointManager.CompiledJoinPoint compiledJp = compileJoinPoint(emittedJoinPoint, compilationLoader);
utility.log(" [compilejar] (genjp) " + file.getName() + ":" + emittedJoinPoint.getJoinPointClassName());
ZipEntry jpZe = new ZipEntry(emittedJoinPoint.getJoinPointClassName()+".class");
jpZe.setSize(compiledJp.bytecode.length);
CRC32 jpCrc = new CRC32();
jpCrc.update(compiledJp.bytecode);
jpZe.setCrc(jpCrc.getValue());
jpZe.setMethod(ze.getMethod());
zos.putNextEntry(jpZe);
zos.write(compiledJp.bytecode, 0, compiledJp.bytecode.length);
CflowCompiler.CompiledCflowAspect[] compiledCflowAspects = compileCflows(compiledJp);
if (compiledCflowAspects.length > 0) {
for (int j = 0; j < compiledCflowAspects.length; j++) {
CflowCompiler.CompiledCflowAspect compiledCflowAspect = compiledCflowAspects[j];
utility.log(" [compilejar] (genjp) (cflow) " + file.getName() + ":" + compiledCflowAspect.className);
ZipEntry cflowZe = new ZipEntry(compiledCflowAspect.className+".class");
cflowZe.setSize(compiledCflowAspect.bytecode.length);
CRC32 cflowCrc = new CRC32();
cflowCrc.update(compiledCflowAspect.bytecode);
cflowZe.setCrc(cflowCrc.getValue());
cflowZe.setMethod(ze.getMethod());
zos.putNextEntry(cflowZe);
zos.write(compiledCflowAspect.bytecode, 0, compiledCflowAspect.bytecode.length);
}
}
}
BIObject obj = DAOFactory.getBIObjectDAO().loadBIObjectById(id);
ObjTemplate templ1 = obj.getActiveTemplate();
byte[] jcrContent1 = templ1.getContent();
String templateFileName = templ1.getName();
ZipEntry entry = new ZipEntry(templateFileName);
String label = obj.getLabel();
zipOut.putNextEntry(entry);
zipOut.write(jcrContent1);
List subReports = DAOFactory.getSubreportDAO().loadSubreportsByMasterRptId(id);
Iterator subReportsIt = subReports.iterator();
while (subReportsIt.hasNext()) {
Subreport subRpt = (Subreport) subReportsIt.next();
BIObject aSubRptObj = DAOFactory.getBIObjectDAO().loadBIObjectById(subRpt.getSub_rpt_id());
// load the subreport template
ObjTemplate templ = aSubRptObj.getActiveTemplate();
byte[] jcrContent = templ.getContent();
templateFileName = templ.getName();
label = aSubRptObj.getLabel();
// put the subreport template in a folder which name is the subreport label
entry = new ZipEntry(label + "/" + templateFileName);
zipOut.putNextEntry(entry);
zipOut.write(jcrContent);
}
String templateFileZIP = (String)request.getAttribute("fileName");
StringBuffer s = new StringBuffer();
for (int i = 0; i < 65535; i++) {
s.append('a');
}
try {
zentry = new ZipEntry(s.toString());
} catch (IllegalArgumentException e) {
fail("Unexpected IllegalArgumentException During Test.");
}
try {
s.append('a');
zentry = new ZipEntry(s.toString());
fail("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
}
try {
String n = null;
zentry = new ZipEntry(n);
fail("NullPointerException not thrown");
} catch (NullPointerException e) {
}
}
manifest.getEntries().put("resource", resourceAttributes);
File targetDir = new File(BASEDIR, "target");
jarFile = new File(targetDir, "resourceFinderTest.jar");
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(jarFile), manifest);
jarOutputStream.putNextEntry(new ZipEntry("resource"));
jarOutputStream.write("resource3".getBytes());
jarOutputStream.putNextEntry(new ZipEntry("jar3"));
jarOutputStream.write("jar3".getBytes());
IoUtil.close(jarOutputStream);
alternateJarFile = new File(targetDir, "alternate.jar");
log.debug(alternateJarFile.getAbsolutePath());
jarOutputStream = new JarOutputStream(new FileOutputStream(alternateJarFile), manifest);
jarOutputStream.putNextEntry(new ZipEntry("resource"));
jarOutputStream.write("resource4".getBytes());
jarOutputStream.putNextEntry(new ZipEntry("jar4"));
jarOutputStream.write("jar4".getBytes());
IoUtil.close(jarOutputStream);
testResource = new File(targetDir, "testResource");
FileOutputStream fileOutputStream = new FileOutputStream(testResource);
monitor.subTask("Adding " + filename);
final byte[] fileContents = readContents(file, new SubProgressMonitor(monitor, SCALE));
// Add contents to zip file
final ZipEntry entry = new ZipEntry(filename);
// file.getModificationStamp() seems to use a different semantic
// for the timestamp
entry.setTime(file.getLocation().toFile().lastModified());
if (fCompress) {
entry.setMethod(ZipEntry.DEFLATED);
} else {
entry.setMethod(ZipEntry.STORED);
entry.setSize(fileContents.length);
final CRC32 checksumCalculator = new CRC32();
checksumCalculator.update(fileContents);
entry.setCrc(checksumCalculator.getValue());
}
stream.putNextEntry(entry);
stream.write(fileContents);
monitor.worked(SCALE);
*/
public static void zip(ZipOutputStream out, File f, String base) throws IOException {
if (f.isDirectory()) {
File[] fl = f.listFiles();
if (!base.equals("")) {
ZipEntry entry = new ZipEntry(base + "/");
entry.setTime(f.lastModified());
out.putNextEntry(entry);
}
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
zip(out, fl[i], base + fl[i].getName());
}
} else {
ZipEntry entry = new ZipEntry(base);
entry.setTime(f.lastModified());
out.putNextEntry(entry);
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(f)));
int b;
while ((b = in.read()) != -1) out.write(b);
in.close();
File licenseFile = new File(file.getParentFile(), file.getName()+".vs.license");
if(licenseFile.exists()) licenseFile.delete();
FileOutputStream fileOutputStream = new FileOutputStream(licenseFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
ZipEntry entry = new ZipEntry("information");
zipOutputStream.putNextEntry(entry);
zipOutputStream.write(data);
zipOutputStream.closeEntry();
entry = new ZipEntry("license");
zipOutputStream.putNextEntry(entry);
zipOutputStream.write(dataSignature);
zipOutputStream.closeEntry();
entry = new ZipEntry("key");
zipOutputStream.putNextEntry(entry);
zipOutputStream.write(key);
zipOutputStream.closeEntry();
zipOutputStream.close();
m.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
m.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, str[0]);
m.getMainAttributes().putValue(Constants.BUNDLE_VERSION, str[1]);
// Put content
JarOutputStream out = new JarOutputStream(os);
ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
out.putNextEntry(e);
m.write(out);
out.closeEntry();
e = new ZipEntry("META-INF/");
out.putNextEntry(e);
e = new ZipEntry("META-INF/" + FeatureDeploymentListener.FEATURE_PATH + "/");
out.putNextEntry(e);
out.closeEntry();
e = new ZipEntry("META-INF/" + FeatureDeploymentListener.FEATURE_PATH + "/" + name);
out.putNextEntry(e);
InputStream fis = url.openStream();
try {
copyInputStream(fis, out);
} finally {
m.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
m.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, str[0]);
m.getMainAttributes().putValue(Constants.BUNDLE_VERSION, str[1]);
// Put content
JarOutputStream out = new JarOutputStream(os);
ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
out.putNextEntry(e);
m.write(out);
out.closeEntry();
e = new ZipEntry("META-INF/");
out.putNextEntry(e);
e = new ZipEntry("META-INF/" + FeatureDeploymentListener.FEATURE_PATH + "/");
out.putNextEntry(e);
out.closeEntry();
e = new ZipEntry("META-INF/" + FeatureDeploymentListener.FEATURE_PATH + "/" + name);
out.putNextEntry(e);
InputStream fis = url.openStream();
try {
copyInputStream(fis, out);
} finally {
writer.write( "_=name:String,pointProperty:Point\n" );
writer.write( "pdsa.0='zero'|POINT(0 0)\n");
writer.write( "pdsa.1='one'|POINT(1 1)\n");
writer.flush();
zout.putNextEntry( new ZipEntry( "pdsa.properties") );
zout.write( bytes.toByteArray() );
bytes.reset();
writer.write( "_=name:String,pointProperty:Point\n" );
writer.write( "pdsb.0='two'|POINT(2 2)\n");
writer.write( "pdsb.1='trhee'|POINT(3 3)\n");
writer.flush();
zout.putNextEntry( new ZipEntry( "pdsb.properties" ) );
zout.write( bytes.toByteArray() );
zout.flush();
zout.close();
}
// BEGIN RELOADING and ZIPPING
// read in and write out .shp
ZipEntry entry = new ZipEntry(name + ".shp");
zipOut.putNextEntry(entry);
InputStream shp_in = new FileInputStream(namePath + ".shp");
readInWriteOutBytes(output, shp_in);
zipOut.closeEntry();
shp_in.close();
// read in and write out .dbf
entry = new ZipEntry(name + ".dbf");
zipOut.putNextEntry(entry);
InputStream dbf_in = new FileInputStream(namePath + ".dbf");
readInWriteOutBytes(output, dbf_in);
zipOut.closeEntry();
dbf_in.close();
writer.write( "_=name:String,pointProperty:Point\n" );
writer.write( "pdsa.0='zero'|POINT(0 0)\n");
writer.write( "pdsa.1='one'|POINT(1 1)\n");
writer.flush();
zout.putNextEntry( new ZipEntry( "pdsa.properties") );
zout.write( bytes.toByteArray() );
bytes.reset();
writer.write( "_=name:String,pointProperty:Point\n" );
writer.write( "pdsb.0='two'|POINT(2 2)\n");
writer.write( "pdsb.1='trhee'|POINT(3 3)\n");
writer.flush();
zout.putNextEntry( new ZipEntry( "pdsb.properties" ) );
zout.write( bytes.toByteArray() );
zout.flush();
zout.close();
{
fos = new FileOutputStream(file);
ZipOutputStream zipos = new ZipOutputStream(fos);
zipos.setMethod(ZipOutputStream.DEFLATED);
ZipEntry propsEntry = new ZipEntry("jasperreports_extension.properties");
zipos.putNextEntry(propsEntry);
Properties props = new Properties();
props.put(PROPERTY_XML_CHART_THEME_REGISTRY_FACTORY, XmlChartThemeExtensionsRegistryFactory.class.getName());
props.put(XML_CHART_THEME_PROPERTY_PREFIX + themeName, themeName + ".jrctx");
props.store(zipos, null);
ZipEntry jrctxEntry = new ZipEntry(themeName + ".jrctx");
zipos.putNextEntry(jrctxEntry);
XmlChartTheme.saveSettings(settings, new OutputStreamWriter(zipos));
zipos.flush();
zipos.finish();
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if(!ze.getName().equals(entry)){
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
copyStream(is, zos);
is.close();
}
}
zos.putNextEntry(new ZipEntry(entry));
InputStream is = new FileInputStream(tmpfile);
copyStream(is, zos);
is.close();
zos.close();
} catch (ZipException e) {
// expected
}
zos = new ZipOutputStream(bos);
zos.putNextEntry(new ZipEntry("XX"));
zos.closeEntry();
zos.close();
// Regression for HARMONY-97
ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
zos.putNextEntry(new ZipEntry("myFile"));
zos.close();
zos.close(); // Should be a no-op
}
/**
*/
protected void writeContentToZipFile(HttpDoc doc, ZipOutputStream zos)
throws IOException {
String contenttype = doc.getHeaderValue(HttpHeader.CONTENT_TYPE);
String extension = getExtensionFromContenttype(contenttype);
ZipEntry zipEntry = new ZipEntry("content" + extension);
long date = doc.getLastModifiedAsMilliSeconds();
if (date < 0) {
date = doc.getDateAsMilliSeconds();
}
zipEntry.setTime(date);
zos.putNextEntry(zipEntry);
zos.write(doc.getContent());
zos.closeEntry();
}
* to new ZipEntry(name).
* @param name the name of the zip entry.
*/
protected ZipEntry createZipEntry(String name)
{
return new ZipEntry(name);
}
}
+ " corrupt archive.");
}
while (sig == cfhSig) {
archive.readFully(cfh);
int off = 0;
ZipEntry ze = new ZipEntry();
int versionMadeBy = ZipShort.getValue(cfh, off);
off += SHORT;
ze.setPlatform((versionMadeBy >> BYTE_SHIFT) & NIBLET_MASK);
off += SHORT; // skip version info
final int generalPurposeFlag = ZipShort.getValue(cfh, off);
final boolean hasUTF8Flag =
(generalPurposeFlag & ZipOutputStream.UFT8_NAMES_FLAG) != 0;
final ZipEncoding entryEncoding =
hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
off += SHORT;
ze.setMethod(ZipShort.getValue(cfh, off));
off += SHORT;
// FIXME this is actually not very cpu cycles friendly as we are converting from
// dos to java while the underlying Sun implementation will convert
// from java to dos time for internal storage...
long time = dosToJavaTime(ZipLong.getValue(cfh, off));
ze.setTime(time);
off += WORD;
ze.setCrc(ZipLong.getValue(cfh, off));
off += WORD;
ze.setCompressedSize(ZipLong.getValue(cfh, off));
off += WORD;
ze.setSize(ZipLong.getValue(cfh, off));
off += WORD;
int fileNameLen = ZipShort.getValue(cfh, off);
off += SHORT;
int extraLen = ZipShort.getValue(cfh, off);
off += SHORT;
int commentLen = ZipShort.getValue(cfh, off);
off += SHORT;
off += SHORT; // disk number
ze.setInternalAttributes(ZipShort.getValue(cfh, off));
off += SHORT;
ze.setExternalAttributes(ZipLong.getValue(cfh, off));
off += WORD;
byte[] fileName = new byte[fileNameLen];
archive.readFully(fileName);
ze.setName(entryEncoding.decode(fileName));
// LFH offset,
OffsetEntry offset = new OffsetEntry();
offset.headerOffset = ZipLong.getValue(cfh, off);
// data offset will be filled later
entries.put(ze, offset);
nameMap.put(ze.getName(), ze);
byte[] cdExtraData = new byte[extraLen];
archive.readFully(cdExtraData);
ze.setCentralDirectoryExtra(cdExtraData);
byte[] comment = new byte[commentLen];
archive.readFully(comment);
ze.setComment(entryEncoding.decode(comment));
archive.readFully(signatureBytes);
sig = ZipLong.getValue(signatureBytes);
if (!hasUTF8Flag && useUnicodeExtraFields) {