Changeset 10759 for extensions/jiwigo-ws-api/src/main/java
- Timestamp:
- May 4, 2011, 7:21:57 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java
r10749 r10759 11 11 import java.io.InputStreamReader; 12 12 import java.io.PrintWriter; 13 import java.io.Reader; 13 14 import java.io.StringReader; 14 15 import java.io.StringWriter; … … 73 74 private static final Logger LOG = LoggerFactory.getLogger(CategoryServiceImpl.class); 74 75 76 // /** 77 // * Transformation of an inpustream into string.<br/> 78 // * useful to read the result of the webservice 79 // * @param input the stream 80 // * @return the string 81 // * @throws IOException 82 // */ 83 // public static String readInputStreamAsString(InputStream input) throws IOException { 84 // StringWriter writer = new StringWriter(); 85 // InputStreamReader streamReader = new InputStreamReader(input); 86 // BufferedReader buffer = new BufferedReader(streamReader); 87 // String line = ""; 88 // while (null != (line = buffer.readLine())) { 89 // writer.write(line); 90 // } 91 // return writer.toString(); 92 // } 93 75 94 /** 76 95 * Transformation of an inpustream into string.<br/> … … 80 99 * @throws IOException 81 100 */ 82 public static String readInputStreamAsString(InputStream input) throws IOException { 83 StringWriter writer = new StringWriter(); 84 InputStreamReader streamReader = new InputStreamReader(input); 85 BufferedReader buffer = new BufferedReader(streamReader); 86 String line = ""; 87 while (null != (line = buffer.readLine())) { 88 writer.write(line); 89 } 90 return writer.toString(); 101 public static String readInputStreamAsString(InputStream is) throws IOException { 102 if (is != null) { 103 Writer writer = new StringWriter(); 104 105 char[] buffer = new char[1024]; 106 try { 107 Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); 108 int n; 109 while ((n = reader.read(buffer)) != -1) { 110 writer.write(buffer, 0, n); 111 } 112 } finally { 113 is.close(); 114 } 115 return writer.toString(); 116 } else { 117 return ""; 118 } 91 119 } 92 120
Note: See TracChangeset
for help on using the changeset viewer.