[
https://issues.apache.org/jira/browse/PDFBOX-6083?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18029191#comment-18029191
]
Tilman Hausherr edited comment on PDFBOX-6083 at 10/13/25 9:02 AM:
-------------------------------------------------------------------
{code:java}
/**
* Same as {@link #read(byte[])} but will loop until exactly length bytes
are read or
* it will throw an exception.
*
* @param b The buffer to write the data to.
* @throws IOException
*/
default void readFully(byte[] b) throws IOException
{
readFully(b, 0, b.length);
}
/**
* Same as {@link #read(byte[], int, int)} but will loop until exactly
length bytes are read or
* it will throw an exception.
*
* @param b The buffer to write the data to.
* @param offset Offset into the buffer to start writing.
* @param length The exact amount of data to attempt to read.
* @throws IOException
*/
default void readFully(byte[] b, int offset, int length) throws IOException
{
if (length() - getPosition() < length)
{
throw new EOFException("Premature end of buffer reached");
}
int bytesReadTotal = 0;
do
{
int bytesReadNow = read(b, offset + bytesReadTotal, length -
bytesReadTotal);
if (bytesReadNow <= 0)
{
throw new EOFException("EOF, should have been detected
earlier");
}
bytesReadTotal += bytesReadNow;
}
while (bytesReadTotal < length);
}
{code}
was (Author: tilman):
{code:java}
/**
* Same as {@link #read(byte[], int, int)} but will loop until exactly
length bytes are read or
* it will throw an exception.
*
* @param b The buffer to write the data to.
* @param offset Offset into the buffer to start writing.
* @param length The exact amount of data to attempt to read.
* @throws IOException
*/
default void readFully(byte[] b, int offset, int length) throws IOException
{
int bytesReadTotal = 0;
do
{
int bytesReadNow = read(b, offset + bytesReadTotal, length -
bytesReadTotal);
if (bytesReadNow < 0)
{
throw new EOFException("EOF");
}
bytesReadTotal += bytesReadNow;
}
while (bytesReadTotal < length);
}
{code}
> optimize DataInputRandomAccessRead
> ----------------------------------
>
> Key: PDFBOX-6083
> URL: https://issues.apache.org/jira/browse/PDFBOX-6083
> Project: PDFBox
> Issue Type: Improvement
> Components: FontBox, IO
> Affects Versions: 3.0.6 PDFBox
> Reporter: Tilman Hausherr
> Priority: Minor
>
> To optimize DataInputRandomAccessRead.readBytes() we need a
> RandomAccessRead.readFully() method.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]