/** * @return The associated {@link Simple8BitZipEncoding}, which * is instantiated if not done so far. */ public synchronized Simple8BitZipEncoding getEncoding() { if (this.encoding == null) { this.encoding = new Simple8BitZipEncoding(this.highChars); } return this.encoding; } }
/** * @see org.apache.tools.zip.ZipEncoding#decode(byte[]) */ public String decode(final byte[] data) throws IOException { final char[] ret = new char[data.length]; for (int i = 0; i < data.length; ++i) { ret[i] = this.decodeByte(data[i]); } return new String(ret); }
/** * @param c The character to encode. * @return Whether the given unicode character is covered by this encoding. */ public boolean canEncodeChar(final char c) { if (c >= 0 && c < 128) { return true; } final Simple8BitChar r = this.encodeHighChar(c); return r != null; }
/** * @see org.apache.tools.zip.ZipEncoding#canEncode(java.lang.String) */ public boolean canEncode(final String name) { for (int i = 0; i < name.length(); ++i) { final char c = name.charAt(i); if (!this.canEncodeChar(c)) { return false; } } return true; }
/** * @see org.apache.tools.zip.ZipEncoding#encode(java.lang.String) */ public ByteBuffer encode(final String name) { ByteBuffer out = ByteBuffer.allocate(name.length() + 6 + (name.length() + 1) / 2); for (int i = 0; i < name.length(); ++i) { final char c = name.charAt(i); if (out.remaining() < 6) { out = ZipEncodingHelper.growBuffer(out, out.position() + 6); } if (!this.pushEncodedChar(out, c)) { ZipEncodingHelper.appendSurrogate(out, c); } } out.limit(out.position()); out.rewind(); return out; }
/** * Pushes the encoded form of the given character to the given byte buffer. * * @param bb The byte buffer to write to. * @param c The character to encode. * @return Whether the given unicode character is covered by this encoding. * If {@code false} is returned, nothing is pushed to the * byte buffer. */ public boolean pushEncodedChar(final ByteBuffer bb, final char c) { if (c >= 0 && c < 128) { bb.put((byte) c); return true; } final Simple8BitChar r = this.encodeHighChar(c); if (r == null) { return false; } bb.put(r.code); return true; }