//throws IOException { /** * Opens the given file for reading, assuming the specified * encoding for file names. * * @param f the archive. * @param encoding the encoding to use for file names, use null * for the platform's default encoding * @param useUnicodeExtraFields whether to use InfoZIP Unicode * Extra Fields (if present) to set the file names. * * @throws IOException if an error occurs while reading the file. */ public ZipFile(java.io.File f, String encoding, bool useUnicodeExtraFields) //throws IOException { this.OFFSET_COMPARATOR = new IAC_OFFSET_COMPARATOR(this); this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.useUnicodeExtraFields = useUnicodeExtraFields; archive = new java.io.RandomAccessFile(f, "r"); bool success = false; try { java.util.Map <ZipArchiveEntry, IAC_NameAndComment> entriesWithoutUTF8Flag = populateFromCentralDirectory(); resolveLocalFileHeaderData(entriesWithoutUTF8Flag); success = true; } finally { if (!success) { try { archive.close(); } catch (java.io.IOException) { // swallow, throw the original exception instead } } } }
/** * @param encoding the encoding to use for file names, use null * for the platform's default encoding * @param useUnicodeExtraFields whether to use InfoZIP Unicode * Extra Fields (if present) to set the file names. * @param allowStoredEntriesWithDataDescriptor whether the stream * will try to read STORED entries that use a data descriptor * @since Apache Commons Compress 1.1 */ public ZipArchiveInputStream(java.io.InputStream inputStream, String encoding, bool useUnicodeExtraFields, bool allowStoredEntriesWithDataDescriptor) { zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.useUnicodeExtraFields = useUnicodeExtraFields; inJ = new java.io.PushbackInputStream(inputStream, buf.Length); this.allowStoredEntriesWithDataDescriptor = allowStoredEntriesWithDataDescriptor; }
/** * @see * org.apache.commons.compress.archivers.zip.ZipEncoding#encode(java.lang.String) */ public java.nio.ByteBuffer encode(String name) { java.nio.charset.CharsetEncoder enc = this.charset.newEncoder(); enc.onMalformedInput(java.nio.charset.CodingErrorAction.REPORT); enc.onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPORT); java.nio.CharBuffer cb = java.nio.CharBuffer.wrap(name); java.nio.ByteBuffer outJ = java.nio.ByteBuffer.allocate(name.length() + (name.length() + 1) / 2); while (cb.remaining() > 0) { java.nio.charset.CoderResult res = enc.encode(cb, outJ, true); if (res.isUnmappable() || res.isMalformed()) { // write the unmappable characters in utf-16 // pseudo-URL encoding style to ByteBuffer. if (res.length() * 6 > outJ.remaining()) { outJ = ZipEncodingHelper.growBuffer(outJ, outJ.position() + res.length() * 6); } for (int i = 0; i < res.length(); ++i) { ZipEncodingHelper.appendSurrogate(outJ, cb.get()); } } else if (res.isOverflow()) { outJ = ZipEncodingHelper.growBuffer(outJ, 0); } else if (res.isUnderflow()) { enc.flush(outJ); break; } } outJ.limit(outJ.position()); outJ.rewind(); return(outJ); }
/** * @see * org.apache.commons.compress.archivers.zip.ZipEncoding#encode(java.lang.String) */ public java.nio.ByteBuffer encode(String name) { java.nio.ByteBuffer outJ = java.nio.ByteBuffer.allocate(name.length() + 6 + (name.length() + 1) / 2); for (int i = 0; i < name.length(); ++i) { char c = name.charAt(i); if (outJ.remaining() < 6) { outJ = ZipEncodingHelper.growBuffer(outJ, outJ.position() + 6); } if (!this.pushEncodedChar(outJ, c)) { ZipEncodingHelper.appendSurrogate(outJ, c); } } outJ.limit(outJ.position()); outJ.rewind(); return(outJ); }
/** * Whether to set the language encoding flag if the file name * encoding is UTF-8. * * <p>Defaults to true.</p> */ public void setUseLanguageEncodingFlag(bool b) { useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding); }
/** * The encoding to use for filenames and the file comment. * * <p>For a list of possible values see <a * href="http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html">http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html</a>. * Defaults to UTF-8.</p> * @param encoding the encoding to use for file names, use null * for the platform's default encoding */ public void setEncoding(String encoding) { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); useUTF8Flag &= ZipEncodingHelper.isUTF8(encoding); }