diff --git a/h2/src/main/org/h2/mvstore/SingleFileStore.java b/h2/src/main/org/h2/mvstore/SingleFileStore.java index 9794c4faff..c4d42533bd 100644 --- a/h2/src/main/org/h2/mvstore/SingleFileStore.java +++ b/h2/src/main/org/h2/mvstore/SingleFileStore.java @@ -238,11 +238,11 @@ public void backup(ZipOutputStream out) throws IOException { boolean before = mvStore.setReuseSpace(false); try { - IOUtils.copy(in, out); + long copied = IOUtils.copy(in, 0, out); mvStore.executeFilestoreOperation(() -> { try { - IOUtils.copy(in, out); + IOUtils.copy(in, copied, out); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/h2/src/main/org/h2/util/IOUtils.java b/h2/src/main/org/h2/util/IOUtils.java index 40bb727bec..128bba0fed 100644 --- a/h2/src/main/org/h2/util/IOUtils.java +++ b/h2/src/main/org/h2/util/IOUtils.java @@ -198,9 +198,9 @@ public static long copy(InputStream in, OutputStream out, long length) * @return the number of bytes copied * @throws IOException on failure */ - public static long copy(FileChannel in, OutputStream out) + public static long copy(FileChannel in, long startAt, OutputStream out) throws IOException { - return copy(in, out, Long.MAX_VALUE); + return copy(in, out, startAt, Long.MAX_VALUE); } /** @@ -213,10 +213,10 @@ public static long copy(FileChannel in, OutputStream out) * @return the number of bytes copied * @throws IOException on failure */ - public static long copy(FileChannel in, OutputStream out, long length) + public static long copy(FileChannel in, OutputStream out, long startAt, long length) throws IOException { try { - long copied = 0; + long copied = startAt; byte[] buffer = new byte[(int) Math.min(length, Constants.IO_BUFFER_SIZE)]; ByteBuffer wrap = ByteBuffer.wrap(buffer); while (length > 0) { @@ -234,7 +234,7 @@ public static long copy(FileChannel in, OutputStream out, long length) wrap.limit((int)length); } } - return copied; + return copied - startAt; } catch (Exception e) { throw DataUtils.convertToIOException(e); }