Changeset 8568 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2015-07-04T22:52:23+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r8567 r8568 14 14 import java.awt.datatransfer.UnsupportedFlavorException; 15 15 import java.io.BufferedReader; 16 import java.io.ByteArrayOutputStream; 16 17 import java.io.Closeable; 17 18 import java.io.File; … … 1337 1338 return hasExtension(file.getName(), extensions); 1338 1339 } 1340 1341 /** 1342 * Reads the input stream and closes the stream at the end of processing (regardless if an exception was thrown) 1343 * 1344 * @param stream 1345 * @return byte array of data in input stream 1346 * @throws IOException 1347 */ 1348 public static byte[] readBytesFromStream(InputStream stream) throws IOException { 1349 try { 1350 ByteArrayOutputStream bout = new ByteArrayOutputStream(stream.available()); 1351 byte[] buffer = new byte[2048]; 1352 boolean finished = false; 1353 do { 1354 int read = stream.read(buffer); 1355 if (read >= 0) { 1356 bout.write(buffer, 0, read); 1357 } else { 1358 finished = true; 1359 } 1360 } while (!finished); 1361 if (bout.size() == 0) 1362 return null; 1363 return bout.toByteArray(); 1364 } finally { 1365 stream.close(); 1366 } 1367 } 1339 1368 }
Note:
See TracChangeset
for help on using the changeset viewer.