jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/packaging/mime/util/ASCIIUtility.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, 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 |
41 |
41 |
42 |
42 |
43 /** |
43 /** |
44 * Convert the bytes within the specified range of the given byte |
44 * Convert the bytes within the specified range of the given byte |
45 * array into a signed integer in the given radix . The range extends |
45 * array into a signed integer in the given radix . The range extends |
46 * from <code>start</code> till, but not including <code>end</code>. <p> |
46 * from <code>start</code> till, but not including <code>end</code>. |
47 * |
47 * |
48 * Based on java.lang.Integer.parseInt() |
48 * Based on java.lang.Integer.parseInt(). |
|
49 * |
|
50 * @param b bytes to convert to integer. |
|
51 * @param start start of the range. |
|
52 * @param end end of the range (not including). |
|
53 * @param radix radix. |
|
54 * |
|
55 * @return integer. |
|
56 * |
49 */ |
57 */ |
50 public static int parseInt(byte[] b, int start, int end, int radix) |
58 public static int parseInt(byte[] b, int start, int end, int radix) |
51 throws NumberFormatException { |
59 throws NumberFormatException { |
52 if (b == null) |
60 if (b == null) |
53 throw new NumberFormatException("null"); |
61 throw new NumberFormatException("null"); |
108 } |
116 } |
109 |
117 |
110 /** |
118 /** |
111 * Convert the bytes within the specified range of the given byte |
119 * Convert the bytes within the specified range of the given byte |
112 * array into a String. The range extends from <code>start</code> |
120 * array into a String. The range extends from <code>start</code> |
113 * till, but not including <code>end</code>. <p> |
121 * till, but not including <code>end</code>. |
|
122 * |
|
123 * @param b bytes to convert to integer. |
|
124 * @param start start of the range. |
|
125 * @param end end of the range (not including). |
|
126 * |
|
127 * @return integer. |
|
128 * |
114 */ |
129 */ |
115 public static String toString(byte[] b, int start, int end) { |
130 public static String toString(byte[] b, int start, int end) { |
116 int size = end - start; |
131 int size = end - start; |
117 char[] theChars = new char[size]; |
132 char[] theChars = new char[size]; |
118 |
133 |
120 theChars[i++] = (char)(b[j++]&0xff); |
135 theChars[i++] = (char)(b[j++]&0xff); |
121 |
136 |
122 return new String(theChars); |
137 return new String(theChars); |
123 } |
138 } |
124 |
139 |
|
140 /** |
|
141 * Encodes specified String into a sequence of bytes using the platform's |
|
142 * default charset, storing the result into a new byte array. |
|
143 * |
|
144 * @param s string to encode into byte array. |
|
145 * |
|
146 * @return byte array. |
|
147 * |
|
148 */ |
125 public static byte[] getBytes(String s) { |
149 public static byte[] getBytes(String s) { |
126 char [] chars= s.toCharArray(); |
150 char [] chars= s.toCharArray(); |
127 int size = chars.length; |
151 int size = chars.length; |
128 byte[] bytes = new byte[size]; |
152 byte[] bytes = new byte[size]; |
129 |
153 |
131 bytes[i] = (byte) chars[i++]; |
155 bytes[i] = (byte) chars[i++]; |
132 return bytes; |
156 return bytes; |
133 } |
157 } |
134 |
158 |
135 /** |
159 /** |
|
160 * Converts input stream to array. |
|
161 * |
|
162 * @param is stream to convert to array. |
|
163 * |
|
164 * @return byte array. |
|
165 * |
|
166 * @throws IOException if an I/O error occurs. |
136 * |
167 * |
137 * @deprecated |
168 * @deprecated |
138 * this is an expensive operation that require an additional |
169 * this is an expensive operation that require an additional |
139 * buffer reallocation just to get the array of an exact size. |
170 * buffer reallocation just to get the array of an exact size. |
140 * Unless you absolutely need the exact size array, don't use this. |
171 * Unless you absolutely need the exact size array, don't use this. |
141 * Use {@link ByteOutputStream} and {@link ByteOutputStream#write(InputStream)}. |
172 * Use {@link ByteOutputStream} and {@link ByteOutputStream#write(InputStream)}. |
142 */ |
173 */ |
|
174 @Deprecated |
143 public static byte[] getBytes(InputStream is) throws IOException { |
175 public static byte[] getBytes(InputStream is) throws IOException { |
144 ByteOutputStream bos = null; |
176 ByteOutputStream bos = null; |
145 try { |
177 try { |
146 bos = new ByteOutputStream(); |
178 bos = new ByteOutputStream(); |
147 bos.write(is); |
179 bos.write(is); |