/** * Construct the cpio input stream with a blocksize of {@link CpioConstants#BLOCK_SIZE BLOCK_SIZE}. * * @param in * The cpio stream * @param blockSize * The block size of the archive. * @param encoding * The encoding of file names to expect - use null for * the platform's default. * @since 1.6 */ public CpioArchiveInputStream(final InputStream in, final int blockSize, final String encoding) { this.in = in; this.blockSize = blockSize; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); }
private static ByteBuffer encodeFully(CharsetEncoder enc, CharBuffer cb, ByteBuffer out) { ByteBuffer o = out; while (cb.hasRemaining()) { CoderResult result = enc.encode(cb, o, false); if (result.isOverflow()) { int increment = estimateIncrementalEncodingSize(enc, cb.remaining()); o = ZipEncodingHelper.growBufferBy(o, increment); } } return o; }
/** * 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(final String encoding) { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); if (useUTF8Flag && !ZipEncodingHelper.isUTF8(encoding)) { useUTF8Flag = false; } }
/** * Whether to set the language encoding flag if the file name * encoding is UTF-8. * * <p>Defaults to true.</p> * * @param b whether to set the language encoding flag if the file * name encoding is UTF-8 */ public void setUseLanguageEncodingFlag(final boolean b) { useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding); }
/** * Instantiates a zip encoding. An NIO based character set encoder/decoder will be returned. * As a special case, if the character set is UTF-8, the nio encoder will be configured replace malformed and * unmappable characters with '?'. This matches existing behavior from the older fallback encoder. * <p> * If the requested characer set cannot be found, the platform default will * be used instead. * </p> * @param name The name of the zip encoding. Specify {@code null} for * the platform's default encoding. * @return A zip encoding for the given encoding name. */ public static ZipEncoding getZipEncoding(final String name) { Charset cs = Charset.defaultCharset(); if (name != null) { try { cs = Charset.forName(name); } catch (UnsupportedCharsetException e) { // NOSONAR we use the default encoding instead } } boolean useReplacement = isUTF8(cs.name()); return new NioZipEncoding(cs, useReplacement); }
/** * Constructor for TarInputStream. * @param is the input stream to use * @param blockSize the block size to use * @param recordSize the record size to use * @param encoding name of the encoding to use for file names * @since 1.4 */ public TarArchiveInputStream(final InputStream is, final int blockSize, final int recordSize, final String encoding) { this.is = is; this.hasHitEOF = false; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.recordSize = recordSize; this.blockSize = blockSize; }
/** * 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(final String encoding) { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); if (useUTF8Flag && !ZipEncodingHelper.isUTF8(encoding)) { useUTF8Flag = false; } }
/** * Whether to set the language encoding flag if the file name * encoding is UTF-8. * * <p>Defaults to true.</p> * * @param b whether to set the language encoding flag if the file * name encoding is UTF-8 */ public void setUseLanguageEncodingFlag(final boolean b) { useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding); }
out = ZipEncodingHelper.growBufferBy(out, totalExtraSpace - out.remaining()); out = ZipEncodingHelper.growBufferBy(out, increment);
this.blockSize = blockSize; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
/** * Instantiates a zip encoding. An NIO based character set encoder/decoder will be returned. * As a special case, if the character set is UTF-8, the nio encoder will be configured replace malformed and * unmappable characters with '?'. This matches existing behavior from the older fallback encoder. * <p> * If the requested characer set cannot be found, the platform default will * be used instead. * </p> * @param name The name of the zip encoding. Specify {@code null} for * the platform's default encoding. * @return A zip encoding for the given encoding name. */ public static ZipEncoding getZipEncoding(final String name) { Charset cs = Charset.defaultCharset(); if (name != null) { try { cs = Charset.forName(name); } catch (UnsupportedCharsetException e) { // NOSONAR we use the default encoding instead } } boolean useReplacement = isUTF8(cs.name()); return new NioZipEncoding(cs, useReplacement); }
private static ByteBuffer encodeFully(CharsetEncoder enc, CharBuffer cb, ByteBuffer out) { ByteBuffer o = out; while (cb.hasRemaining()) { CoderResult result = enc.encode(cb, o, false); if (result.isOverflow()) { int increment = estimateIncrementalEncodingSize(enc, cb.remaining()); o = ZipEncodingHelper.growBufferBy(o, increment); } } return o; }
/** * Create an instance using the specified encoding * @param inputStream the stream to wrap * @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 1.1 */ public ZipArchiveInputStream(final InputStream inputStream, final String encoding, final boolean useUnicodeExtraFields, final boolean allowStoredEntriesWithDataDescriptor) { this.encoding = encoding; zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.useUnicodeExtraFields = useUnicodeExtraFields; in = new PushbackInputStream(inputStream, buf.capacity()); this.allowStoredEntriesWithDataDescriptor = allowStoredEntriesWithDataDescriptor; // haven't read anything so far buf.limit(0); }
out = ZipEncodingHelper.growBufferBy(out, totalExtraSpace - out.remaining()); out = ZipEncodingHelper.growBufferBy(out, increment);
/** * Constructor for TarArchiveOutputStream. * * @param os the output stream to use * @param blockSize the block size to use. Must be a multiple of 512 bytes. * @param encoding name of the encoding to use for file names * @since 1.4 */ public TarArchiveOutputStream(final OutputStream os, final int blockSize, final String encoding) { int realBlockSize; if (BLOCK_SIZE_UNSPECIFIED == blockSize) { realBlockSize = RECORD_SIZE; } else { realBlockSize = blockSize; } if (realBlockSize <=0 || realBlockSize % RECORD_SIZE != 0) { throw new IllegalArgumentException("Block size must be a multiple of 512 bytes. Attempt to use set size of " + blockSize); } out = new FixedLengthBlockOutputStream(countingOut = new CountingOutputStream(os), RECORD_SIZE); this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.recordBuf = new byte[RECORD_SIZE]; this.recordsPerBlock = realBlockSize / RECORD_SIZE; }
private ZipFile(final SeekableByteChannel channel, final String archiveName, final String encoding, final boolean useUnicodeExtraFields, final boolean closeOnError) throws IOException { this.archiveName = archiveName; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.useUnicodeExtraFields = useUnicodeExtraFields; archive = channel; boolean success = false; try { final Map<ZipArchiveEntry, NameAndComment> entriesWithoutUTF8Flag = populateFromCentralDirectory(); resolveLocalFileHeaderData(entriesWithoutUTF8Flag); success = true; } finally { closed = !success; if (!success && closeOnError) { IOUtils.closeQuietly(archive); } } }
this.hasHitEOF = false; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
private byte[] encodeArchiveEntry( String payload, String encoding ) throws IOException { ZipEncoding enc = ZipEncodingHelper.getZipEncoding( encoding ); ByteBuffer encodedPayloadByteBuffer = enc.encode( payload ); byte[] encodedPayloadBytes = new byte[encodedPayloadByteBuffer.limit()]; encodedPayloadByteBuffer.get( encodedPayloadBytes ); return encodedPayloadBytes; }
/** * Constructor for TarInputStream. * @param is the input stream to use * @param blockSize the block size to use * @param recordSize the record size to use * @param encoding name of the encoding to use for file names * @since 1.4 */ public TarArchiveInputStream(final InputStream is, final int blockSize, final int recordSize, final String encoding) { this.is = is; this.hasHitEOF = false; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.recordSize = recordSize; this.blockSize = blockSize; }
/** * Construct the cpio input stream with a blocksize of {@link CpioConstants#BLOCK_SIZE BLOCK_SIZE}. * * @param in * The cpio stream * @param blockSize * The block size of the archive. * @param encoding * The encoding of file names to expect - use null for * the platform's default. * @since 1.6 */ public CpioArchiveInputStream(final InputStream in, final int blockSize, final String encoding) { this.in = in; this.blockSize = blockSize; this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); }