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/06/01 19:04:17 UTC
[commons-imaging] branch master updated: Rename method
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 a9047f5f Rename method
a9047f5f is described below
commit a9047f5f037c9d3cec83fa9572a8e51c2054fa0d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jun 1 15:04:13 2023 -0400
Rename method
---
.../commons/imaging/bytesource/ByteSource.java | 2 +-
.../imaging/bytesource/ByteSourceArray.java | 2 +-
.../commons/imaging/bytesource/ByteSourceFile.java | 2 +-
.../imaging/bytesource/ByteSourceInputStream.java | 28 +++++++++++-----------
.../imaging/formats/pcx/PcxImageParser.java | 2 +-
.../commons/imaging/formats/tiff/TiffReader.java | 10 ++++----
6 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java b/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java
index a5043459..1ac1fc82 100644
--- a/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java
+++ b/src/main/java/org/apache/commons/imaging/bytesource/ByteSource.java
@@ -76,7 +76,7 @@ public abstract class ByteSource {
* @return the byte source length
* @throws IOException if it fails to read the byte source data
*/
- public abstract long getLength() throws IOException;
+ public abstract long size() throws IOException;
@Override
public String toString() {
diff --git a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceArray.java b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceArray.java
index 11693643..346dee4f 100644
--- a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceArray.java
+++ b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceArray.java
@@ -56,7 +56,7 @@ class ByteSourceArray extends ByteSource {
}
@Override
- public long getLength() {
+ public long size() {
return bytes.length;
}
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 1accc3a9..6bde65c8 100644
--- a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceFile.java
+++ b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceFile.java
@@ -54,7 +54,7 @@ class ByteSourceFile extends ByteSource {
}
@Override
- public long getLength() {
+ public long size() {
return file.length();
}
diff --git a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceInputStream.java b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceInputStream.java
index 18ee478b..be755a09 100644
--- a/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceInputStream.java
+++ b/src/main/java/org/apache/commons/imaging/bytesource/ByteSourceInputStream.java
@@ -184,7 +184,7 @@ class ByteSourceInputStream extends ByteSource {
// We include a separate check for int overflow.
if ((from < 0) || (length < 0)
|| (from + length < 0)
- || (from + length > getLength())) {
+ || (from + length > size())) {
throw new ImagingException("Could not read block (block start: "
+ from + ", block length: " + length
+ ", data length: " + streamLength + ").");
@@ -219,19 +219,6 @@ class ByteSourceInputStream extends ByteSource {
return new CacheReadingInputStream();
}
- @Override
- public long getLength() throws IOException {
- if (streamLength >= 0) {
- return streamLength;
- }
-
- try (InputStream cis = getInputStream()) {
- final long result = IOUtils.consume(cis);
- streamLength = result;
- return result;
- }
- }
-
private CacheBlock readBlock() throws IOException {
if (null == readBuffer) {
readBuffer = new byte[BLOCK_SIZE];
@@ -251,4 +238,17 @@ class ByteSourceInputStream extends ByteSource {
return new CacheBlock(result);
}
+ @Override
+ public long size() throws IOException {
+ if (streamLength >= 0) {
+ return streamLength;
+ }
+
+ try (InputStream cis = getInputStream()) {
+ final long result = IOUtils.consume(cis);
+ streamLength = result;
+ return result;
+ }
+ }
+
}
diff --git a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
index 80333d72..65004538 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
@@ -276,7 +276,7 @@ public class PcxImageParser extends ImageParser<PcxImagingParameters> {
private int[] read256ColorPaletteFromEndOfFile(final ByteSource byteSource)
throws IOException {
try (InputStream stream = byteSource.getInputStream()) {
- final long toSkip = byteSource.getLength() - 769;
+ final long toSkip = byteSource.size() - 769;
skipBytes(stream, (int) toSkip);
return read256ColorPalette(stream);
}
diff --git a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
index bec96508..96e939c2 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
@@ -134,8 +134,8 @@ public class TiffReader extends BinaryFileParser {
final long offset = element.offset;
int length = element.length;
// In case the length is not correct, adjust it and check if the last read byte actually is the end of the image
- if (offset + length > byteSource.getLength()) {
- length = (int) (byteSource.getLength() - offset);
+ if (offset + length > byteSource.size()) {
+ length = (int) (byteSource.size() - offset);
}
final byte[] data = byteSource.getByteArray(offset, length);
// check if the last read byte is actually the end of the image data
@@ -283,7 +283,7 @@ public class TiffReader extends BinaryFileParser {
visited.add(directoryOffset);
try (InputStream is = byteSource.getInputStream()) {
- if (directoryOffset >= byteSource.getLength()) {
+ if (directoryOffset >= byteSource.size()) {
return true;
}
@@ -328,13 +328,13 @@ public class TiffReader extends BinaryFileParser {
final long valueLength = count * fieldType.getSize();
final byte[] value;
if (valueLength > TIFF_ENTRY_MAX_VALUE_LENGTH) {
- if ((offset < 0) || (offset + valueLength) > byteSource.getLength()) {
+ if ((offset < 0) || (offset + valueLength) > byteSource.size()) {
if (strict) {
throw new IOException(
"Attempt to read byte range starting from " + offset + " "
+ "of length " + valueLength + " "
+ "which is outside the file's size of "
- + byteSource.getLength());
+ + byteSource.size());
}
// corrupt field, ignore it
continue;