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 2023/05/31 22:03:05 UTC
[commons-imaging] branch master updated: Replace magic string with API call
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-imaging.git
The following commit(s) were added to refs/heads/master by this push:
new bd860df2 Replace magic string with API call
bd860df2 is described below
commit bd860df2d8ff9de4cde86a3451fac0c28c8c2260
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 31 18:02:56 2023 -0400
Replace magic string with API call
---
.../apache/commons/imaging/bytesource/ByteSourceFile.java | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceFile.java b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceFile.java
index fdc3de81..d541e907 100644
--- a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceFile.java
+++ b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceFile.java
@@ -25,6 +25,7 @@ import java.io.RandomAccessFile;
import org.apache.commons.imaging.ImagingException;
import org.apache.commons.imaging.common.BinaryFunctions;
+import org.apache.commons.io.RandomAccessFileMode;
class ByteSourceFile extends ByteSource {
private final File file;
@@ -36,17 +37,14 @@ class ByteSourceFile extends ByteSource {
@Override
public byte[] getBlock(final long from, final int length) throws IOException {
- try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
+ try (RandomAccessFile raf = RandomAccessFileMode.READ_ONLY.create(file)) {
// We include a separate check for int overflow.
- if ((from < 0) || (length < 0) || (from + length < 0)
- || (from + length > raf.length())) {
- throw new ImagingException("Could not read block (block start: "
- + from + ", block length: " + length
- + ", data length: " + raf.length() + ").");
+ if ((from < 0) || (length < 0) || (from + length < 0) || (from + length > raf.length())) {
+ throw new ImagingException(
+ "Could not read block (block start: " + from + ", block length: " + length + ", data length: " + raf.length() + ").");
}
- return BinaryFunctions.getRAFBytes(raf, from, length,
- "Could not read value from file");
+ return BinaryFunctions.getRAFBytes(raf, from, length, "Could not read value from file");
}
}