diff options
author | Ade Lee <alee@redhat.com> | 2011-12-08 21:15:59 -0500 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2011-12-08 21:15:59 -0500 |
commit | 171aaece4f23709d33d180cf36eb3af5e454b0c9 (patch) | |
tree | 1485f9f0a7bd10de4ff25030db575dbb8dafae74 /pki/base/util/src/netscape/security/util/ByteToCharUnicode.java | |
parent | adad2fcee8a29fdb82376fbce07dedb11fccc182 (diff) | |
download | pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.gz pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.xz pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.zip |
Revert "Formatting"
This reverts commit 32150d3ee32f8ac27118af7c792794b538c78a2f.
Diffstat (limited to 'pki/base/util/src/netscape/security/util/ByteToCharUnicode.java')
-rw-r--r-- | pki/base/util/src/netscape/security/util/ByteToCharUnicode.java | 244 |
1 files changed, 124 insertions, 120 deletions
diff --git a/pki/base/util/src/netscape/security/util/ByteToCharUnicode.java b/pki/base/util/src/netscape/security/util/ByteToCharUnicode.java index 7b2a8e6a..312b8a22 100644 --- a/pki/base/util/src/netscape/security/util/ByteToCharUnicode.java +++ b/pki/base/util/src/netscape/security/util/ByteToCharUnicode.java @@ -16,7 +16,6 @@ // All rights reserved. // --- END COPYRIGHT BLOCK --- package netscape.security.util; - import sun.io.ByteToCharUnicodeBig; import sun.io.ByteToCharUnicodeLittle; import sun.io.ConversionBufferFullException; @@ -24,21 +23,22 @@ import sun.io.MalformedInputException; /** * Convert byte arrays containing Unicode characters into arrays of actual - * Unicode characters, sensing the byte order automatically. To force a + * Unicode characters, sensing the byte order automatically. To force a * particular byte order, use either the "UnicodeBig" or the "UnicodeLittle" * encoding. - * + * * If the first character is a byte order mark, it will be interpreted and - * discarded. Otherwise, the byte order is assumed to be BigEndian. Either way, - * the byte order is decided by the first character. Later byte order marks will - * be passed through as characters (if they indicate the same byte order) or - * will cause an error (if they indicate the other byte order). - * + * discarded. Otherwise, the byte order is assumed to be BigEndian. + * Either way, the byte order is decided by the first character. Later + * byte order marks will be passed through as characters (if they indicate + * the same byte order) or will cause an error (if they indicate the other + * byte order). + * * @see ByteToCharUnicodeLittle * @see ByteToCharUnicodeBig - * - * @version 1.3, 96/11/23 - * @author Mark Reinhold + * + * @version 1.3, 96/11/23 + * @author Mark Reinhold */ public class ByteToCharUnicode extends sun.io.ByteToCharConverter { @@ -53,131 +53,135 @@ public class ByteToCharUnicode extends sun.io.ByteToCharConverter { int byteOrder; public ByteToCharUnicode() { - byteOrder = AUTO; + byteOrder = AUTO; } public String getCharacterEncoding() { - switch (byteOrder) { - case BIG: - return "UnicodeBig"; - case LITTLE: - return "UnicodeLittle"; - default: - return "Unicode"; - } + switch (byteOrder) { + case BIG: return "UnicodeBig"; + case LITTLE: return "UnicodeLittle"; + default: return "Unicode"; + } } boolean started = false; int leftOverByte; boolean leftOver = false; - public int convert(byte[] in, int inOff, int inEnd, char[] out, int outOff, - int outEnd) throws ConversionBufferFullException, - MalformedInputException { - byteOff = inOff; - charOff = outOff; - - if (inOff >= inEnd) - return 0; - - int b1, b2; - int bc = 0; - int inI = inOff, outI = outOff; - - if (leftOver) { - b1 = leftOverByte & 0xff; - leftOver = false; - } else - b1 = in[inI++] & 0xff; - bc = 1; - - if (!started) { /* Read possible initial byte-order mark */ - if (inI < inEnd) { - b2 = in[inI++] & 0xff; - bc = 2; - - char c = (char) ((b1 << 8) | b2); - int bo = AUTO; - - if (c == BYTE_ORDER_MARK) - bo = BIG; - else if (c == REVERSED_MARK) - bo = LITTLE; - - if (byteOrder == AUTO) { - if (bo == AUTO) { + public int convert(byte[] in, int inOff, int inEnd, + char[] out, int outOff, int outEnd) + throws ConversionBufferFullException, MalformedInputException + { + byteOff = inOff; + charOff = outOff; + + if (inOff >= inEnd) + return 0; + + int b1, b2; + int bc = 0; + int inI = inOff, outI = outOff; + + if (leftOver) { + b1 = leftOverByte & 0xff; + leftOver = false; + } + else + b1 = in[inI++] & 0xff; + bc = 1; + + if (!started) { /* Read possible initial byte-order mark */ + if (inI < inEnd) { + b2 = in[inI++] & 0xff; + bc = 2; + + char c = (char) ((b1 << 8) | b2); + int bo = AUTO; + + if (c == BYTE_ORDER_MARK) + bo = BIG; + else if (c == REVERSED_MARK) + bo = LITTLE; + + if (byteOrder == AUTO) { + if (bo == AUTO) { bo = BIG; // BigEndian by default - } - byteOrder = bo; - if (inI < inEnd) { - b1 = in[inI++] & 0xff; - bc = 1; - } - } else if (bo == AUTO) { - inI--; - bc = 1; - } else if (byteOrder == bo) { - if (inI < inEnd) { - b1 = in[inI++] & 0xff; - bc = 1; - } - } else { - badInputLength = bc; - throw new MalformedInputException( - "Incorrect byte-order mark"); - } - - started = true; - } - } - - /* Loop invariant: (b1 contains the next input byte) && (bc == 1) */ - while (inI < inEnd) { - b2 = in[inI++] & 0xff; - bc = 2; - - char c; - if (byteOrder == BIG) - c = (char) ((b1 << 8) | b2); - else - c = (char) ((b2 << 8) | b1); - - if (c == REVERSED_MARK) - throw new MalformedInputException("Reversed byte-order mark"); - - if (outI >= outEnd) - throw new ConversionBufferFullException(); - out[outI++] = c; - byteOff = inI; - charOff = outI; - - if (inI < inEnd) { - b1 = in[inI++] & 0xff; - bc = 1; - } - } - - if (bc == 1) { - leftOverByte = b1; - leftOver = true; - } - - return outI - outOff; + } + byteOrder = bo; + if (inI < inEnd) { + b1 = in[inI++] & 0xff; + bc = 1; + } + } + else if (bo == AUTO) { + inI--; + bc = 1; + } + else if (byteOrder == bo) { + if (inI < inEnd) { + b1 = in[inI++] & 0xff; + bc = 1; + } + } + else { + badInputLength = bc; + throw new + MalformedInputException("Incorrect byte-order mark"); + } + + started = true; + } + } + + /* Loop invariant: (b1 contains the next input byte) && (bc == 1) */ + while (inI < inEnd) { + b2 = in[inI++] & 0xff; + bc = 2; + + char c; + if (byteOrder == BIG) + c = (char) ((b1 << 8) | b2); + else + c = (char) ((b2 << 8) | b1); + + if (c == REVERSED_MARK) + throw new + MalformedInputException("Reversed byte-order mark"); + + if (outI >= outEnd) + throw new ConversionBufferFullException(); + out[outI++] = c; + byteOff = inI; + charOff = outI; + + if (inI < inEnd) { + b1 = in[inI++] & 0xff; + bc = 1; + } + } + + if (bc == 1) { + leftOverByte = b1; + leftOver = true; + } + + return outI - outOff; } public void reset() { - leftOver = false; - byteOff = charOff = 0; + leftOver = false; + byteOff = charOff = 0; } public int flush(char buf[], int off, int len) - throws MalformedInputException { - if (leftOver) { - reset(); - throw new MalformedInputException(); - } - byteOff = charOff = 0; - return 0; + throws MalformedInputException + { + if (leftOver) { + reset(); + throw new MalformedInputException(); + } + byteOff = charOff = 0; + return 0; } } |