You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/12/29 14:45:59 UTC

[commons-io] branch master updated: Use Arrays.copyOf() and copyOfRange()

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ccf989e Use Arrays.copyOf() and copyOfRange()
7ccf989e is described below

commit 7ccf989e31b81ab9d21cae35cf24ceb661e94847
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 29 09:45:55 2022 -0500

    Use Arrays.copyOf() and copyOfRange()
---
 .../java/org/apache/commons/io/input/ReversedLinesFileReader.java  | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
index 79aa6225..e6a4fce2 100644
--- a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
+++ b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
@@ -29,6 +29,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -90,8 +91,7 @@ public class ReversedLinesFileReader implements Closeable {
             final int lineLengthBytes = currentLastBytePos + 1;
             if (lineLengthBytes > 0) {
                 // create left over for next block
-                leftOver = IOUtils.byteArray(lineLengthBytes);
-                System.arraycopy(data, 0, leftOver, 0, lineLengthBytes);
+                leftOver = Arrays.copyOf(data, lineLengthBytes);
             } else {
                 leftOver = null;
             }
@@ -149,8 +149,7 @@ public class ReversedLinesFileReader implements Closeable {
                     if (lineLengthBytes < 0) {
                         throw new IllegalStateException("Unexpected negative line length=" + lineLengthBytes);
                     }
-                    final byte[] lineData = IOUtils.byteArray(lineLengthBytes);
-                    System.arraycopy(data, lineStart, lineData, 0, lineLengthBytes);
+                    final byte[] lineData = Arrays.copyOfRange(data, lineStart, lineStart + lineLengthBytes);
 
                     line = new String(lineData, charset);