Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
jhy committed Aug 7, 2024
1 parent 59fee40 commit 5071f6c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jspecify.annotations.Nullable;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/jsoup/internal/SimpleBufferedInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@

/**
A simple implemented of a buffered input stream, in which we can control the byte[] buffer to recycle it. Not safe for
use between threads; no sync or locks. The buffer is borrowed on initial demand in fill. */
use between threads; no sync or locks. The buffer is borrowed on initial demand in fill.
@since 1.18.2
*/
class SimpleBufferedInput extends FilterInputStream {
static final int BufferSize = DefaultBufferSize;
static final SoftPool<byte[]> BufferPool = new SoftPool<>(() -> new byte[BufferSize]);

byte @Nullable [] byteBuf; // the byte buffer; recycled via SoftPool. Created in fill if required
int bufPos;
int bufLength;
int bufMark = -1;
private byte @Nullable [] byteBuf; // the byte buffer; recycled via SoftPool. Created in fill if required
private int bufPos;
private int bufLength;
private int bufMark = -1;

SimpleBufferedInput(InputStream in) {
super(in);
Expand Down Expand Up @@ -107,6 +109,7 @@ public int available() throws IOException {
return in.available();
}

@SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") // explicitly not synced
@Override
public void mark(int readlimit) {

Check warning

Code scanning / CodeQL

Non-synchronized override of synchronized method Warning

Method 'mark' overrides a synchronized method in
java.io.FilterInputStream
but is not synchronized.
if (readlimit > BufferSize) {
Expand All @@ -115,6 +118,7 @@ public void mark(int readlimit) {
bufMark = bufPos;
}

@SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") // explicitly not synced
@Override
public void reset() throws IOException {

Check warning

Code scanning / CodeQL

Non-synchronized override of synchronized method Warning

Method 'reset' overrides a synchronized method in
java.io.FilterInputStream
but is not synchronized.
if (bufMark < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jsoup/internal/SoftPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expensive objects (buffers, etc.) between invocations (the ThreadLocal), but als
they are no longer in use.
<p>Like a ThreadLocal, should be stored in a static field.</p>
@param <T> the type of object to pool.
@since 1.18.1
@since 1.18.2
*/
public class SoftPool<T> {
final ThreadLocal<SoftReference<Stack<T>>> threadLocalStack;
Expand Down

0 comments on commit 5071f6c

Please sign in to comment.