move methods around
@@ -67,33 +67,6 @@ public boolean canEncode(final String name) {
return enc.canEncode(name);
}
- private CharsetEncoder newEncoder() {
- if (useReplacement) {
- return charset.newEncoder()
- .onMalformedInput(CodingErrorAction.REPLACE)
- .onUnmappableCharacter(CodingErrorAction.REPLACE)
- .replaceWith(REPLACEMENT_BYTES);
- } else {
- return charset.newEncoder()
- .onMalformedInput(CodingErrorAction.REPORT)
- .onUnmappableCharacter(CodingErrorAction.REPORT);
- }
- }
-
- private CharsetDecoder newDecoder() {
- if (!useReplacement) {
- return this.charset.newDecoder()
- .onMalformedInput(CodingErrorAction.REPORT)
- .onUnmappableCharacter(CodingErrorAction.REPORT);
- } else {
- return charset.newDecoder()
- .onMalformedInput(CodingErrorAction.REPLACE)
- .onUnmappableCharacter(CodingErrorAction.REPLACE)
- .replaceWith(REPLACEMENT_STRING);
- }
- }
-
-
/**
* @see ZipEncoding#encode(java.lang.String)
*/
@@ -150,6 +123,16 @@ public ByteBuffer encode(final String name) {
return out;
}
+ /**
+ * @see
+ * ZipEncoding#decode(byte[])
+ */
+ @Override
+ public String decode(final byte[] data) throws IOException {
+ return newDecoder()
+ .decode(ByteBuffer.wrap(data)).toString();
+ }
+
private static ByteBuffer encodeFully(CharsetEncoder enc, CharBuffer cb, ByteBuffer out) {
while (cb.hasRemaining()) {
CoderResult result = enc.encode(cb, out, false);
@@ -178,6 +161,32 @@ private static CharBuffer encodeSurrogate(CharBuffer cb, char c) {
return cb;
}
+ private CharsetEncoder newEncoder() {
+ if (useReplacement) {
+ return charset.newEncoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE)
+ .replaceWith(REPLACEMENT_BYTES);
+ } else {
+ return charset.newEncoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT);
+ }
+ }
+
+ private CharsetDecoder newDecoder() {
+ if (!useReplacement) {
+ return this.charset.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT);
+ } else {
+ return charset.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE)
+ .replaceWith(REPLACEMENT_STRING);
+ }
+ }
+
/**
* Estimate the initial encoded size (in bytes) for a character buffer.
* <p>
@@ -207,14 +216,4 @@ private static int estimateIncrementalEncodingSize(CharsetEncoder enc, int charC
return (int) Math.ceil(charCount * enc.averageBytesPerChar());
}
- /**
- * @see
- * ZipEncoding#decode(byte[])
- */
- @Override
- public String decode(final byte[] data) throws IOException {
- return newDecoder()
- .decode(ByteBuffer.wrap(data)).toString();
- }
-
}
