equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
31 import java.io.InputStream; |
31 import java.io.InputStream; |
32 import java.io.PrintStream; |
32 import java.io.PrintStream; |
33 import java.io.OutputStream; |
33 import java.io.OutputStream; |
34 import java.io.IOException; |
34 import java.io.IOException; |
35 import java.nio.ByteBuffer; |
35 import java.nio.ByteBuffer; |
|
36 |
|
37 import static java.nio.charset.StandardCharsets.ISO_8859_1; |
36 |
38 |
37 /** |
39 /** |
38 * This class encodes a buffer into the classic: "Hexadecimal Dump" format of |
40 * This class encodes a buffer into the classic: "Hexadecimal Dump" format of |
39 * the past. It is useful for analyzing the contents of binary buffers. |
41 * the past. It is useful for analyzing the contents of binary buffers. |
40 * The format produced is as follows: |
42 * The format produced is as follows: |
181 * A 'streamless' version of encode that simply takes a buffer of |
183 * A 'streamless' version of encode that simply takes a buffer of |
182 * bytes and returns a string containing the encoded buffer. |
184 * bytes and returns a string containing the encoded buffer. |
183 */ |
185 */ |
184 public String encode(byte aBuffer[]) { |
186 public String encode(byte aBuffer[]) { |
185 ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
187 ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
186 ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer); |
188 ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer); |
187 String retVal = null; |
|
188 try { |
189 try { |
189 encode(inStream, outStream); |
190 encode(inStream, outStream); |
190 // explicit ascii->unicode conversion |
191 // explicit ascii->unicode conversion |
191 retVal = outStream.toString("ISO-8859-1"); |
192 return outStream.toString(ISO_8859_1); |
192 } catch (Exception IOException) { |
193 } catch (IOException ignore) { |
193 // This should never happen. |
194 // This should never happen. |
194 throw new Error("CharacterEncoder.encode internal error"); |
195 throw new Error("CharacterEncoder.encode internal error"); |
195 } |
196 } |
196 return (retVal); |
|
197 } |
197 } |
198 |
198 |
199 /** |
199 /** |
200 * Return a byte array from the remaining bytes in this ByteBuffer. |
200 * Return a byte array from the remaining bytes in this ByteBuffer. |
201 * <P> |
201 * <P> |