Skip to content

Commit 13d3090

Browse files
committed
Fix TrinoInputStream.available implementations
The contract for this method is > Returns an estimate of the number of bytes that can be read (or > skipped over) from this input stream without blocking only the in-memory buffered bytes are available in that sense.
1 parent 800ff7c commit 13d3090

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

lib/trino-filesystem-cache-alluxio/src/main/java/io/trino/filesystem/alluxio/AlluxioInputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.IOException;
2828

2929
import static com.google.common.base.Verify.verify;
30-
import static com.google.common.primitives.Ints.saturatedCast;
3130
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_LOCATION;
3231
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_READ_POSITION;
3332
import static io.trino.filesystem.tracing.CacheSystemAttributes.CACHE_FILE_READ_SIZE;
@@ -70,9 +69,10 @@ public AlluxioInputStream(Tracer tracer, TrinoInputFile inputFile, String key, U
7069
public int available()
7170
throws IOException
7271
{
72+
// Not needed per contract, but complies with AbstractTestTrinoFileSystem expectations easier.
73+
// It's easer to just check "is open?" in available() than refactor that test.
7374
ensureOpen();
74-
75-
return saturatedCast(fileLength - position);
75+
return super.available();
7676
}
7777

7878
@Override

lib/trino-filesystem-gcs/src/main/java/io/trino/filesystem/gcs/GcsInputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import com.google.cloud.ReadChannel;
1717
import com.google.cloud.storage.Blob;
18-
import com.google.common.primitives.Ints;
1918
import io.trino.filesystem.TrinoInputStream;
2019
import io.trino.filesystem.encryption.EncryptionKey;
2120

@@ -63,9 +62,10 @@ public GcsInputStream(GcsLocation location, Blob blob, int readBlockSizeBytes, O
6362
public int available()
6463
throws IOException
6564
{
65+
// Not needed per contract, but complies with AbstractTestTrinoFileSystem expectations easier.
66+
// It's easer to just check "is open?" in available() than refactor that test.
6667
ensureOpen();
67-
repositionStream();
68-
return Ints.saturatedCast(fileSize - currentPosition);
68+
return super.available();
6969
}
7070

7171
@Override

lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalInputStream.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
package io.trino.filesystem.local;
1515

16-
import com.google.common.primitives.Ints;
1716
import io.trino.filesystem.Location;
1817
import io.trino.filesystem.TrinoInputStream;
1918

@@ -53,7 +52,7 @@ public int available()
5352
throws IOException
5453
{
5554
ensureOpen();
56-
return Ints.saturatedCast(fileLength - position);
55+
return input.available();
5756
}
5857

5958
@Override

0 commit comments

Comments
 (0)