From fa353ad87ce7e38954ef8854a91036db70061ccb Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Mon, 1 Mar 2021 13:24:30 +0200 Subject: [PATCH] small fixes --- .../src/main/java/net/osmand/util/Algorithms.java | 15 +++++---------- .../plus/onlinerouting/engine/GpxEngine.java | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index 8954e2d61b..36c0034a26 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -565,16 +565,11 @@ public class Algorithms { } } - public static ByteArrayInputStream createByteArrayIS(InputStream inputStream) throws IOException { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - int i = 0; - while ((i = inputStream.read()) != -1) { - outputStream.write(i); - } - inputStream.close(); - - byte[] byteArray = outputStream.toByteArray(); - return new ByteArrayInputStream(byteArray); + public static ByteArrayInputStream createByteArrayIS(InputStream in) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + streamCopy(in, out); + in.close(); + return new ByteArrayInputStream(out.toByteArray()); } @SuppressWarnings("ResultOfMethodCallIgnored") diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GpxEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GpxEngine.java index eac4771ba3..736d09611a 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GpxEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GpxEngine.java @@ -95,7 +95,7 @@ public class GpxEngine extends OnlineRoutingEngine { } private GPXFile parseGpx(@NonNull String content) { - InputStream gpxStream = null; + InputStream gpxStream; try { gpxStream = new ByteArrayInputStream(content.getBytes("UTF-8")); return GPXUtilities.loadGPXFile(gpxStream);