From 106ddb84a07ead9a17090dd7c8b4afa45266b4a6 Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Sun, 29 Nov 2026 21:33:02 +0900 Subject: [PATCH 1/2] chore: bump version to 0.8.0-SNAPSHOT The next release changes the return type of CopyUtil.copy, which breaks binary compatibility, so it is a minor version bump. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9b8b86f..254ea23 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ corelib jar CodeLibs Core Library - 0.7.3-SNAPSHOT + 0.8.0-SNAPSHOT Core library providing essential utilities and functionalities. https://github.com/codelibs/corelib 2012 From 8e49bf91c664926054544aa152ea25b44a2da83d Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Sun, 29 Nov 2026 21:33:02 +0900 Subject: [PATCH 2/2] feat(io)!: return the copied count as a long from CopyUtil.copy CopyUtil.copy returned an int, so since #25 a copy larger than Integer.MAX_VALUE bytes or characters reported Integer.MAX_VALUE instead of the real count. Every copy method and copyInternal now return a long with the exact count, and the cap is removed. BREAKING CHANGE: the return type of every CopyUtil.copy overload and of the protected copyInternal methods changes from int to long. Code that assigns the result to an int no longer compiles, and classes compiled against an earlier corelib fail with NoSuchMethodError at the call site until they are recompiled, even when they ignore the result. --- .../java/org/codelibs/core/io/CopyUtil.java | 123 ++++++++---------- .../org/codelibs/core/io/CopyUtilTest.java | 48 +++---- 2 files changed, 79 insertions(+), 92 deletions(-) diff --git a/src/main/java/org/codelibs/core/io/CopyUtil.java b/src/main/java/org/codelibs/core/io/CopyUtil.java index dacfebb..1f941e6 100644 --- a/src/main/java/org/codelibs/core/io/CopyUtil.java +++ b/src/main/java/org/codelibs/core/io/CopyUtil.java @@ -111,9 +111,6 @@ *

* Any {@link IOException} thrown by these methods is wrapped and thrown as an {@link IORuntimeException}. *

- *

- * The returned count is capped at {@link Integer#MAX_VALUE}: content larger than that is still copied in full. - *

* * @author koichik */ @@ -141,7 +138,7 @@ protected CopyUtil() { * @param out the output stream (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final InputStream in, final OutputStream out) { + public static long copy(final InputStream in, final OutputStream out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -170,7 +167,7 @@ public static int copy(final InputStream in, final OutputStream out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final InputStream in, final Writer out) { + public static long copy(final InputStream in, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -189,7 +186,7 @@ public static int copy(final InputStream in, final Writer out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final InputStream in, final String encoding, final Writer out) { + public static long copy(final InputStream in, final String encoding, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -211,7 +208,7 @@ public static int copy(final InputStream in, final String encoding, final Writer * @param out the file (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final InputStream in, final File out) { + public static long copy(final InputStream in, final File out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -239,7 +236,7 @@ public static int copy(final InputStream in, final File out) { * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final InputStream in, final StringBuilder out) { + public static long copy(final InputStream in, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -258,7 +255,7 @@ public static int copy(final InputStream in, final StringBuilder out) { * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final InputStream in, final String encoding, final StringBuilder out) { + public static long copy(final InputStream in, final String encoding, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -280,7 +277,7 @@ public static int copy(final InputStream in, final String encoding, final String * @param out the output stream (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final Reader in, final OutputStream out) { + public static long copy(final Reader in, final OutputStream out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -299,7 +296,7 @@ public static int copy(final Reader in, final OutputStream out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final Reader in, final OutputStream out, final String encoding) { + public static long copy(final Reader in, final OutputStream out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -321,7 +318,7 @@ public static int copy(final Reader in, final OutputStream out, final String enc * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final Reader in, final Writer out) { + public static long copy(final Reader in, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -341,7 +338,7 @@ public static int copy(final Reader in, final Writer out) { * @param out the file (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final Reader in, final File out) { + public static long copy(final Reader in, final File out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -361,7 +358,7 @@ public static int copy(final Reader in, final File out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final Reader in, final File out, final String encoding) { + public static long copy(final Reader in, final File out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -387,7 +384,7 @@ public static int copy(final Reader in, final File out, final String encoding) { * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final Reader in, final StringBuilder out) { + public static long copy(final Reader in, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -407,7 +404,7 @@ public static int copy(final Reader in, final StringBuilder out) { * @param out the output stream (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final File in, final OutputStream out) { + public static long copy(final File in, final OutputStream out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -435,7 +432,7 @@ public static int copy(final File in, final OutputStream out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final File in, final Writer out) { + public static long copy(final File in, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -458,7 +455,7 @@ public static int copy(final File in, final Writer out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final File in, final String encoding, final Writer out) { + public static long copy(final File in, final String encoding, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -481,7 +478,7 @@ public static int copy(final File in, final String encoding, final Writer out) { * @param out the output file (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final File in, final File out) { + public static long copy(final File in, final File out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -506,7 +503,7 @@ public static int copy(final File in, final File out) { * @param out the output file (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final File in, final String encoding, final File out) { + public static long copy(final File in, final String encoding, final File out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -532,7 +529,7 @@ public static int copy(final File in, final String encoding, final File out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final File in, final File out, final String encoding) { + public static long copy(final File in, final File out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -559,7 +556,7 @@ public static int copy(final File in, final File out, final String encoding) { * @param outputEncoding the output file encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final File in, final String inputEncoding, final File out, final String outputEncoding) { + public static long copy(final File in, final String inputEncoding, final File out, final String outputEncoding) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("inputEncoding", inputEncoding); assertArgumentNotNull("out", out); @@ -588,7 +585,7 @@ public static int copy(final File in, final String inputEncoding, final File out * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final File in, final StringBuilder out) { + public static long copy(final File in, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -608,7 +605,7 @@ public static int copy(final File in, final StringBuilder out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final File in, final String encoding, final StringBuilder out) { + public static long copy(final File in, final String encoding, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -634,7 +631,7 @@ public static int copy(final File in, final String encoding, final StringBuilder * @param out the output stream (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final URL in, final OutputStream out) { + public static long copy(final URL in, final OutputStream out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -662,7 +659,7 @@ public static int copy(final URL in, final OutputStream out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final URL in, final Writer out) { + public static long copy(final URL in, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -685,7 +682,7 @@ public static int copy(final URL in, final Writer out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final URL in, final String encoding, final Writer out) { + public static long copy(final URL in, final String encoding, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -708,7 +705,7 @@ public static int copy(final URL in, final String encoding, final Writer out) { * @param out the file (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final URL in, final File out) { + public static long copy(final URL in, final File out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -733,7 +730,7 @@ public static int copy(final URL in, final File out) { * @param out the output file (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final URL in, final String encoding, final File out) { + public static long copy(final URL in, final String encoding, final File out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -759,7 +756,7 @@ public static int copy(final URL in, final String encoding, final File out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final URL in, final File out, final String encoding) { + public static long copy(final URL in, final File out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -786,7 +783,7 @@ public static int copy(final URL in, final File out, final String encoding) { * @param outputEncoding the file encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final URL in, final String inputEncoding, final File out, final String outputEncoding) { + public static long copy(final URL in, final String inputEncoding, final File out, final String outputEncoding) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("inputEncoding", inputEncoding); assertArgumentNotNull("out", out); @@ -815,7 +812,7 @@ public static int copy(final URL in, final String inputEncoding, final File out, * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final URL in, final StringBuilder out) { + public static long copy(final URL in, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -835,7 +832,7 @@ public static int copy(final URL in, final StringBuilder out) { * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final URL in, final String encoding, final StringBuilder out) { + public static long copy(final URL in, final String encoding, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -861,7 +858,7 @@ public static int copy(final URL in, final String encoding, final StringBuilder * @param out the output stream (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final byte[] in, final OutputStream out) { + public static long copy(final byte[] in, final OutputStream out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -885,7 +882,7 @@ public static int copy(final byte[] in, final OutputStream out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final byte[] in, final Writer out) { + public static long copy(final byte[] in, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -904,7 +901,7 @@ public static int copy(final byte[] in, final Writer out) { * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final byte[] in, final String encoding, final Writer out) { + public static long copy(final byte[] in, final String encoding, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -923,7 +920,7 @@ public static int copy(final byte[] in, final String encoding, final Writer out) * @param out the file (must not be {@literal null}) * @return the number of bytes copied */ - public static int copy(final byte[] in, final File out) { + public static long copy(final byte[] in, final File out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -945,7 +942,7 @@ public static int copy(final byte[] in, final File out) { * @param out the file (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final byte[] in, final String encoding, final File out) { + public static long copy(final byte[] in, final String encoding, final File out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -967,7 +964,7 @@ public static int copy(final byte[] in, final String encoding, final File out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final byte[] in, final File out, final String encoding) { + public static long copy(final byte[] in, final File out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -990,7 +987,7 @@ public static int copy(final byte[] in, final File out, final String encoding) { * @param outputEncoding the output encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final byte[] in, final String inputEncoding, final File out, final String outputEncoding) { + public static long copy(final byte[] in, final String inputEncoding, final File out, final String outputEncoding) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("inputEncoding", inputEncoding); assertArgumentNotNull("out", out); @@ -1015,7 +1012,7 @@ public static int copy(final byte[] in, final String inputEncoding, final File o * @param out the {@link StringBuilder} (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final byte[] in, final StringBuilder out) { + public static long copy(final byte[] in, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -1031,7 +1028,7 @@ public static int copy(final byte[] in, final StringBuilder out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final byte[] in, final String encoding, final StringBuilder out) { + public static long copy(final byte[] in, final String encoding, final StringBuilder out) { assertArgumentNotNull("in", in); assertArgumentNotEmpty("encoding", encoding); assertArgumentNotNull("out", out); @@ -1053,7 +1050,7 @@ public static int copy(final byte[] in, final String encoding, final StringBuild * @param out the output stream (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final String in, final OutputStream out) { + public static long copy(final String in, final OutputStream out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -1072,7 +1069,7 @@ public static int copy(final String in, final OutputStream out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final String in, final OutputStream out, final String encoding) { + public static long copy(final String in, final OutputStream out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -1094,7 +1091,7 @@ public static int copy(final String in, final OutputStream out, final String enc * @param out the writer (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final String in, final Writer out) { + public static long copy(final String in, final Writer out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -1111,7 +1108,7 @@ public static int copy(final String in, final Writer out) { * @param out the file (must not be {@literal null}) * @return the number of characters copied */ - public static int copy(final String in, final File out) { + public static long copy(final String in, final File out) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); @@ -1131,7 +1128,7 @@ public static int copy(final String in, final File out) { * @param encoding the encoding (must not be {@literal null} or empty) * @return the number of characters copied */ - public static int copy(final String in, final File out, final String encoding) { + public static long copy(final String in, final File out, final String encoding) { assertArgumentNotNull("in", in); assertArgumentNotNull("out", out); assertArgumentNotEmpty("encoding", encoding); @@ -1157,7 +1154,7 @@ public static int copy(final String in, final File out, final String encoding) { * @param out the output stream * @return the number of bytes copied */ - protected static int copyInternal(final InputStream in, final OutputStream out) { + protected static long copyInternal(final InputStream in, final OutputStream out) { try { final byte[] buf = new byte[DEFAULT_BUF_SIZE]; int len; @@ -1167,7 +1164,7 @@ protected static int copyInternal(final InputStream in, final OutputStream out) amount += len; } out.flush(); - return toCount(amount); + return amount; } catch (final IOException e) { throw new IORuntimeException(e); } @@ -1183,7 +1180,7 @@ protected static int copyInternal(final InputStream in, final OutputStream out) * @param out the output stream * @return the number of bytes copied */ - protected static int copyInternal(final FileInputStream in, final OutputStream out) { + protected static long copyInternal(final FileInputStream in, final OutputStream out) { try { final FileChannel channel = in.getChannel(); final ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_BUF_SIZE); @@ -1196,7 +1193,7 @@ protected static int copyInternal(final FileInputStream in, final OutputStream o amount += len; } out.flush(); - return toCount(amount); + return amount; } catch (final IOException e) { throw new IORuntimeException(e); } @@ -1212,7 +1209,7 @@ protected static int copyInternal(final FileInputStream in, final OutputStream o * @param out the file output stream * @return the number of bytes copied */ - protected static int copyInternal(final InputStream in, final FileOutputStream out) { + protected static long copyInternal(final InputStream in, final FileOutputStream out) { // Write at the stream's current position so that content already written to it is kept. return copyInternal(in, (OutputStream) out); } @@ -1227,20 +1224,10 @@ protected static int copyInternal(final InputStream in, final FileOutputStream o * @param out the file output stream * @return the number of bytes copied */ - protected static int copyInternal(final FileInputStream in, final FileOutputStream out) { + protected static long copyInternal(final FileInputStream in, final FileOutputStream out) { final FileChannel ic = in.getChannel(); final FileChannel oc = out.getChannel(); - return toCount(ChannelUtil.transfer(ic, oc)); - } - - /** - * Converts the number of copied bytes or characters to the count returned by the copy methods. - * - * @param amount the number of bytes or characters copied - * @return {@code amount}, or {@link Integer#MAX_VALUE} if it does not fit in an {@code int} - */ - private static int toCount(final long amount) { - return (int) Math.min(amount, Integer.MAX_VALUE); + return ChannelUtil.transfer(ic, oc); } /** @@ -1253,7 +1240,7 @@ private static int toCount(final long amount) { * @param out the writer * @return the number of characters copied */ - protected static int copyInternal(final Reader in, final Writer out) { + protected static long copyInternal(final Reader in, final Writer out) { try { final char[] buf = new char[DEFAULT_BUF_SIZE]; int len; @@ -1263,7 +1250,7 @@ protected static int copyInternal(final Reader in, final Writer out) { amount += len; } out.flush(); - return toCount(amount); + return amount; } catch (final IOException e) { throw new IORuntimeException(e); } @@ -1276,7 +1263,7 @@ protected static int copyInternal(final Reader in, final Writer out) { * @param out the {@link StringBuilder} * @return the number of characters copied */ - protected static int copyInternal(final Reader in, final StringBuilder out) { + protected static long copyInternal(final Reader in, final StringBuilder out) { try { final char[] buf = new char[DEFAULT_BUF_SIZE]; int len; @@ -1285,7 +1272,7 @@ protected static int copyInternal(final Reader in, final StringBuilder out) { out.append(buf, 0, len); amount += len; } - return toCount(amount); + return amount; } catch (final IOException e) { throw new IORuntimeException(e); } diff --git a/src/test/java/org/codelibs/core/io/CopyUtilTest.java b/src/test/java/org/codelibs/core/io/CopyUtilTest.java index ef4d98a..a78881a 100644 --- a/src/test/java/org/codelibs/core/io/CopyUtilTest.java +++ b/src/test/java/org/codelibs/core/io/CopyUtilTest.java @@ -64,8 +64,8 @@ public class CopyUtilTest { */ @Test public void testIsToOs() throws Exception { - final int result = copy(is, os); - assertThat(result, is(srcBytes.length)); + final long result = copy(is, os); + assertThat(result, is((long) srcBytes.length)); assertThat(os.toByteArray(), is(srcBytes)); } @@ -74,8 +74,8 @@ public void testIsToOs() throws Exception { */ @Test public void testReaderToWriter() throws Exception { - final int result = copy(reader, writer); - assertThat(result, is(srcString.length())); + final long result = copy(reader, writer); + assertThat(result, is((long) srcString.length())); assertThat(writer.toString(), is(srcString)); } @@ -84,8 +84,8 @@ public void testReaderToWriter() throws Exception { */ @Test public void testBytesToOs() throws Exception { - final int result = copy(srcBytes, os); - assertThat(result, is(srcBytes.length)); + final long result = copy(srcBytes, os); + assertThat(result, is((long) srcBytes.length)); assertThat(os.toByteArray(), is(srcBytes)); } @@ -94,8 +94,8 @@ public void testBytesToOs() throws Exception { */ @Test public void testStringToWriter() throws Exception { - final int result = copy(srcString, writer); - assertThat(result, is(srcString.length())); + final long result = copy(srcString, writer); + assertThat(result, is((long) srcString.length())); assertThat(writer.toString(), is(srcString)); } @@ -104,8 +104,8 @@ public void testStringToWriter() throws Exception { */ @Test public void testReaderToStringBuilder() throws Exception { - final int result = copy(reader, builder); - assertThat(result, is(srcString.length())); + final long result = copy(reader, builder); + assertThat(result, is((long) srcString.length())); assertThat(new String(builder), is(srcString)); } @@ -114,8 +114,8 @@ public void testReaderToStringBuilder() throws Exception { */ @Test public void testUrlToWriter() throws Exception { - final int result = copy(url, "UTF-8", writer); - assertThat(result, is(urlString.length())); + final long result = copy(url, "UTF-8", writer); + assertThat(result, is((long) urlString.length())); assertThat(writer.toString(), is(urlString)); } @@ -124,8 +124,8 @@ public void testUrlToWriter() throws Exception { */ @Test public void testFileToWriter() throws Exception { - final int result = copy(inputFile, "UTF-8", writer); - assertThat(result, is(urlString.length())); + final long result = copy(inputFile, "UTF-8", writer); + assertThat(result, is((long) urlString.length())); assertThat(writer.toString(), is(urlString)); } @@ -134,8 +134,8 @@ public void testFileToWriter() throws Exception { */ @Test public void testFileToFile() throws Exception { - int result = copy(inputFile, outputFile); - assertThat(result, is(urlString.getBytes("UTF-8").length)); + long result = copy(inputFile, outputFile); + assertThat(result, is((long) urlString.getBytes("UTF-8").length)); result = copy(outputFile, "UTF-8", writer); assertThat(writer.toString(), is(urlString)); @@ -146,8 +146,8 @@ public void testFileToFile() throws Exception { */ @Test public void testFileToFile_Encoding() throws Exception { - int result = copy(inputFile, "UTF-8", outputFile, "Shift_JIS"); - assertThat(result, is(urlString.length())); + long result = copy(inputFile, "UTF-8", outputFile, "Shift_JIS"); + assertThat(result, is((long) urlString.length())); result = copy(outputFile, "Shift_JIS", writer); assertThat(writer.toString(), is(urlString)); @@ -158,8 +158,8 @@ public void testFileToFile_Encoding() throws Exception { */ @Test public void testUrlToFile() throws Exception { - int result = copy(url, outputFile); - assertThat(result, is(urlString.getBytes("UTF-8").length)); + long result = copy(url, outputFile); + assertThat(result, is((long) urlString.getBytes("UTF-8").length)); result = copy(outputFile, "UTF-8", writer); assertThat(writer.toString(), is(urlString)); @@ -184,8 +184,8 @@ public void testFileToFile_LargeContentIsComplete() throws Exception { fos.write(expected); } - final int result = copy(src, dest); - assertThat(result, is(expected.length)); + final long result = copy(src, dest); + assertThat(result, is((long) expected.length)); assertThat(FileUtil.readBytes(dest, expected.length), is(expected)); } finally { src.delete(); @@ -204,8 +204,8 @@ public void testIsToFileOs_KeepsWrittenContent() throws Exception { try { try (FileOutputStream fos = new FileOutputStream(dest)) { fos.write(new byte[] { 'H', 'D' }); - final int result = copy(is, fos); - assertThat(result, is(srcBytes.length)); + final long result = copy(is, fos); + assertThat(result, is((long) srcBytes.length)); } final byte[] expected = new byte[srcBytes.length + 2]; expected[0] = 'H';