@@ -110,18 +110,10 @@ public InputStream getInputStream(){
110110 //** getText
111111 //**************************************************************************
112112 /** Used read through the entire response stream and cast it to a string.
113- * The string is encoded using ISO-8859-1 character encoding.
113+ * The string is encoded using UTF-8 character encoding.
114114 */
115115 public String getText (){
116- try {
117- return getText ("ISO-8859-1" );
118- }
119- catch (Exception e ){}
120- try {
121- return getBytes (true ).toString ();
122- }
123- catch (Exception e ){}
124- return null ;
116+ return getText ("UTF-8" );
125117 }
126118
127119
@@ -183,7 +175,12 @@ public ByteArrayOutputStream getBytes(){
183175 * @param deflate Option to decompress a gzip encoded response
184176 */
185177 public ByteArrayOutputStream getBytes (boolean deflate ){
178+ return getBytes (this .getInputStream (), deflate );
179+ }
180+
186181
182+
183+ private ByteArrayOutputStream getBytes (InputStream inputStream , boolean deflate ){
187184 ByteArrayOutputStream bas = new ByteArrayOutputStream ();
188185 String encoding = this .getHeader ("Content-Encoding" );
189186 if (deflate && encoding !=null ){
@@ -194,7 +191,7 @@ public ByteArrayOutputStream getBytes(boolean deflate){
194191 int len ;
195192
196193 try {
197- gzipInputStream = new GZIPInputStream (this . getInputStream () );
194+ gzipInputStream = new GZIPInputStream (inputStream );
198195 while ((len = gzipInputStream .read (buf )) > 0 ) {
199196 bas .write (buf , 0 , len );
200197 }
@@ -216,12 +213,12 @@ public ByteArrayOutputStream getBytes(boolean deflate){
216213 }
217214 else {
218215
219- InputStream inputStream = null ;
216+ // InputStream inputStream = null;
220217 byte [] buf = new byte [1024 ];
221218 int len =0 ;
222219
223220 try {
224- inputStream = conn .getInputStream ();
221+ // inputStream = conn.getInputStream();
225222 while ((len =inputStream .read (buf ,0 ,1024 ))>-1 ) {
226223 bas .write (buf ,0 ,len );
227224 }
@@ -283,6 +280,35 @@ public InputStream getErrorStream(){
283280 }
284281 }
285282
283+ //**************************************************************************
284+ //** getErrorMessage
285+ //**************************************************************************
286+ /** Used read through the entire error stream and cast it to a string.
287+ * The string is encoded using UTF-8 character encoding.
288+ */
289+ public String getErrorMessage (){
290+ return getErrorMessage ("UTF-8" );
291+ }
292+
293+
294+ //**************************************************************************
295+ //** getErrorMessage
296+ //**************************************************************************
297+ /** Used read through the entire error stream and cast it to a string.
298+ *
299+ * @param charsetName Name of the character encoding used to read the file.
300+ * Examples include UTF-8 and ISO-8859-1
301+ */
302+ public String getErrorMessage (String charsetName ){
303+ try {
304+ return getBytes (getErrorStream (), true ).toString (charsetName );
305+ }
306+ catch (Exception e ){
307+ e .printStackTrace ();
308+ }
309+ return null ;
310+ }
311+
286312
287313
288314
0 commit comments