本文整理了Java中org.apache.commons.compress.archivers.zip.ZipEncoding.decode()
方法的一些代码示例,展示了ZipEncoding.decode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEncoding.decode()
方法的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipEncoding
类名称:ZipEncoding
方法名:decode
暂无
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Decodes a byte array to a string.
*/
static String decode(final ZipEncoding encoding, final byte[] b, final int offset, final int len)
throws IOException {
return encoding.decode(Arrays.copyOfRange(b, offset, offset + len));
}
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Parse an entry name from a buffer.
* Parsing stops when a NUL is found
* or the buffer length is reached.
*
* @param buffer The buffer from which to parse.
* @param offset The offset into the buffer from which to parse.
* @param length The maximum number of bytes to parse.
* @param encoding name of the encoding to use for file names
* @since 1.4
* @return The entry name.
* @throws IOException on error
*/
public static String parseName(final byte[] buffer, final int offset,
final int length,
final ZipEncoding encoding)
throws IOException {
int len = 0;
for (int i = offset; len < length && buffer[i] != 0; i++) {
len++;
}
if (len > 0) {
final byte[] b = new byte[len];
System.arraycopy(buffer, offset, b, 0, len);
return encoding.decode(b);
}
return "";
}
代码示例来源:origin: org.apache.commons/commons-compress
private String readCString(final int length) throws IOException {
// don't include trailing NUL in file name to decode
final byte tmpBuffer[] = new byte[length - 1];
readFully(tmpBuffer, 0, tmpBuffer.length);
this.in.read();
return zipEncoding.decode(tmpBuffer);
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* If the stored CRC matches the one of the given name, return the
* Unicode name of the given field.
*
* <p>If the field is null or the CRCs don't match, return null
* instead.</p>
*/
private static
String getUnicodeStringIfOriginalMatches(final AbstractUnicodeExtraField f,
final byte[] orig) {
if (f != null) {
final CRC32 crc32 = new CRC32();
crc32.update(orig);
final long origCRC32 = crc32.getValue();
if (origCRC32 == f.getNameCRC32()) {
try {
return ZipEncodingHelper
.UTF8_ZIP_ENCODING.decode(f.getUnicodeName());
} catch (final IOException ex) {
// UTF-8 unsupported? should be impossible the
// Unicode*ExtraField must contain some bad bytes
// TODO log this anywhere?
return null;
}
}
}
return null;
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* <p>
* Convenience method to return the entry's content as a String if isUnixSymlink()
* returns true for it, otherwise returns null.
* </p>
*
* <p>This method assumes the symbolic link's file name uses the
* same encoding that as been specified for this ZipFile.</p>
*
* @param entry ZipArchiveEntry object that represents the symbolic link
* @return entry's content as a String
* @throws IOException problem with content's input stream
* @since 1.5
*/
public String getUnixSymlink(final ZipArchiveEntry entry) throws IOException {
if (entry != null && entry.isUnixSymlink()) {
try (InputStream in = getInputStream(entry)) {
return zipEncoding.decode(IOUtils.toByteArray(in));
}
}
return null;
}
代码示例来源:origin: org.apache.commons/commons-compress
currEntry.setLinkName(zipEncoding.decode(longLinkData));
currEntry.setName(zipEncoding.decode(longNameData));
代码示例来源:origin: org.apache.commons/commons-compress
ze.setName(entryEncoding.decode(fileName), fileName);
ze.setComment(entryEncoding.decode(comment));
代码示例来源:origin: org.apache.commons/commons-compress
current.entry.setName(entryEncoding.decode(fileName), fileName);
if (hasUTF8Flag) {
current.entry.setNameSource(ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Decodes a byte array to a string.
*/
static String decode(final ZipEncoding encoding, final byte[] b, final int offset, final int len)
throws IOException {
return encoding.decode(Arrays.copyOfRange(b, offset, offset + len));
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
private String readCString(final int length) throws IOException {
// don't include trailing NUL in file name to decode
final byte tmpBuffer[] = new byte[length - 1];
readFully(tmpBuffer, 0, tmpBuffer.length);
this.in.read();
return zipEncoding.decode(tmpBuffer);
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Parse an entry name from a buffer.
* Parsing stops when a NUL is found
* or the buffer length is reached.
*
* @param buffer The buffer from which to parse.
* @param offset The offset into the buffer from which to parse.
* @param length The maximum number of bytes to parse.
* @param encoding name of the encoding to use for file names
* @since 1.4
* @return The entry name.
* @throws IOException on error
*/
public static String parseName(final byte[] buffer, final int offset,
final int length,
final ZipEncoding encoding)
throws IOException {
int len = 0;
for (int i = offset; len < length && buffer[i] != 0; i++) {
len++;
}
if (len > 0) {
final byte[] b = new byte[len];
System.arraycopy(buffer, offset, b, 0, len);
return encoding.decode(b);
}
return "";
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* If the stored CRC matches the one of the given name, return the
* Unicode name of the given field.
*
* <p>If the field is null or the CRCs don't match, return null
* instead.</p>
*/
private static
String getUnicodeStringIfOriginalMatches(final AbstractUnicodeExtraField f,
final byte[] orig) {
if (f != null) {
final CRC32 crc32 = new CRC32();
crc32.update(orig);
final long origCRC32 = crc32.getValue();
if (origCRC32 == f.getNameCRC32()) {
try {
return ZipEncodingHelper
.UTF8_ZIP_ENCODING.decode(f.getUnicodeName());
} catch (final IOException ex) {
// UTF-8 unsupported? should be impossible the
// Unicode*ExtraField must contain some bad bytes
// TODO log this anywhere?
return null;
}
}
}
return null;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* <p>
* Convenience method to return the entry's content as a String if isUnixSymlink()
* returns true for it, otherwise returns null.
* </p>
*
* <p>This method assumes the symbolic link's file name uses the
* same encoding that as been specified for this ZipFile.</p>
*
* @param entry ZipArchiveEntry object that represents the symbolic link
* @return entry's content as a String
* @throws IOException problem with content's input stream
* @since 1.5
*/
public String getUnixSymlink(final ZipArchiveEntry entry) throws IOException {
if (entry != null && entry.isUnixSymlink()) {
try (InputStream in = getInputStream(entry)) {
return zipEncoding.decode(IOUtils.toByteArray(in));
}
}
return null;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
currEntry.setLinkName(zipEncoding.decode(longLinkData));
currEntry.setName(zipEncoding.decode(longNameData));
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
ze.setName(entryEncoding.decode(fileName), fileName);
ze.setComment(entryEncoding.decode(comment));
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
current.entry.setName(entryEncoding.decode(fileName), fileName);
if (hasUTF8Flag) {
current.entry.setNameSource(ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
内容来源于网络,如有侵权,请联系作者删除!