Decode chars from byte buffer using UTF8 encoding. This operation is performance-critical since a jar file contains a large number of strings for the name of each file in the archive. This routine therefore avoids using the expensive utf8Decoder when decoding is straightforward. @param buffer the
(byte[] buffer, int pos, int length)
| 720 | * @return a String that contains the decoded characters. |
| 721 | */ |
| 722 | private String decodeChars(byte[] buffer, int pos, int length) |
| 723 | throws IOException |
| 724 | { |
| 725 | String result; |
| 726 | int i=length - 1; |
| 727 | while ((i >= 0) && (buffer[i] <= 0x7f)) |
| 728 | { |
| 729 | i--; |
| 730 | } |
| 731 | if (i < 0) |
| 732 | { |
| 733 | result = stringFromSubarray(buffer, 0, pos, length); |
| 734 | } |
| 735 | else |
| 736 | { |
| 737 | ByteBuffer bufferBuffer = ByteBuffer.wrap(buffer, pos, length); |
| 738 | // if (utf8Decoder == null) |
| 739 | // utf8Decoder = UTF8CHARSET.newDecoder(); |
| 740 | // utf8Decoder.reset(); |
| 741 | // char [] characters = utf8Decoder.decode(bufferBuffer).array(); |
| 742 | // char [] characters = utf8Decoder.decode(bufferBuffer).array(); |
| 743 | |
| 744 | ByteArrayInputStream in = new ByteArrayInputStream(buffer); |
| 745 | AlbiteStreamReader r = |
| 746 | new AlbiteStreamReader(in, Encodings.UTF_8); |
| 747 | char[] characters = r.read(buffer.length); |
| 748 | result = String.valueOf(characters); |
| 749 | } |
| 750 | return result; |
| 751 | } |
| 752 | |
| 753 | String readString(int length) throws IOException |
| 754 | { |
no test coverage detected