Skip to content

Commit

Permalink
Enable some methods in ByteStreams for j2kt-native
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 731426628
  • Loading branch information
stefanhaustein authored and Google Java Core Libraries committed Feb 26, 2025
1 parent 9d9a7cd commit 5d7daae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion android/guava/src/com/google/common/io/ByteStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
* @author Colin Decker
* @since 1.0
*/
@J2ktIncompatible
@GwtIncompatible
public final class ByteStreams {

Expand Down Expand Up @@ -132,6 +131,7 @@ public static long copy(InputStream from, OutputStream to) throws IOException {
* @return the number of bytes copied
* @throws IOException if an I/O error occurs
*/
@J2ktIncompatible
@CanIgnoreReturnValue
public static long copy(ReadableByteChannel from, WritableByteChannel to) throws IOException {
checkNotNull(from);
Expand Down Expand Up @@ -301,6 +301,7 @@ public static long exhaust(InputStream in) throws IOException {
* Returns a new {@link ByteArrayDataInput} instance to read from the {@code bytes} array from the
* beginning.
*/
@J2ktIncompatible
public static ByteArrayDataInput newDataInput(byte[] bytes) {
return newDataInput(new ByteArrayInputStream(bytes));
}
Expand All @@ -312,6 +313,7 @@ public static ByteArrayDataInput newDataInput(byte[] bytes) {
* @throws IndexOutOfBoundsException if {@code start} is negative or greater than the length of
* the array
*/
@J2ktIncompatible
public static ByteArrayDataInput newDataInput(byte[] bytes, int start) {
checkPositionIndex(start, bytes.length);
return newDataInput(new ByteArrayInputStream(bytes, start, bytes.length - start));
Expand All @@ -324,10 +326,12 @@ public static ByteArrayDataInput newDataInput(byte[] bytes, int start) {
*
* @since 17.0
*/
@J2ktIncompatible
public static ByteArrayDataInput newDataInput(ByteArrayInputStream byteArrayInputStream) {
return new ByteArrayDataInputStream(checkNotNull(byteArrayInputStream));
}

@J2ktIncompatible
private static class ByteArrayDataInputStream implements ByteArrayDataInput {
final DataInput input;

Expand Down Expand Up @@ -474,6 +478,7 @@ public String readUTF() {
}

/** Returns a new {@link ByteArrayDataOutput} instance with a default size. */
@J2ktIncompatible
public static ByteArrayDataOutput newDataOutput() {
return newDataOutput(new ByteArrayOutputStream());
}
Expand All @@ -484,6 +489,7 @@ public static ByteArrayDataOutput newDataOutput() {
*
* @throws IllegalArgumentException if {@code size} is negative
*/
@J2ktIncompatible
public static ByteArrayDataOutput newDataOutput(int size) {
// When called at high frequency, boxing size generates too much garbage,
// so avoid doing that if we can.
Expand All @@ -505,10 +511,12 @@ public static ByteArrayDataOutput newDataOutput(int size) {
*
* @since 17.0
*/
@J2ktIncompatible
public static ByteArrayDataOutput newDataOutput(ByteArrayOutputStream byteArrayOutputStream) {
return new ByteArrayDataOutputStream(checkNotNull(byteArrayOutputStream));
}

@J2ktIncompatible
private static class ByteArrayDataOutputStream implements ByteArrayDataOutput {

final DataOutput output;
Expand Down Expand Up @@ -693,10 +701,12 @@ public static OutputStream nullOutputStream() {
* @return a length-limited {@link InputStream}
* @since 14.0 (since 1.0 as com.google.common.io.LimitInputStream)
*/
@J2ktIncompatible
public static InputStream limit(InputStream in, long limit) {
return new LimitedInputStream(in, limit);
}

@J2ktIncompatible
private static final class LimitedInputStream extends FilterInputStream {

private long left;
Expand Down Expand Up @@ -879,6 +889,7 @@ private static long skipSafely(InputStream in, long n) throws IOException {
*/
@CanIgnoreReturnValue // some processors won't return a useful result
@ParametricNullness
@J2ktIncompatible
public static <T extends @Nullable Object> T readBytes(
InputStream input, ByteProcessor<T> processor) throws IOException {
checkNotNull(input);
Expand Down
13 changes: 12 additions & 1 deletion guava/src/com/google/common/io/ByteStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
* @author Colin Decker
* @since 1.0
*/
@J2ktIncompatible
@GwtIncompatible
public final class ByteStreams {

Expand Down Expand Up @@ -132,6 +131,7 @@ public static long copy(InputStream from, OutputStream to) throws IOException {
* @return the number of bytes copied
* @throws IOException if an I/O error occurs
*/
@J2ktIncompatible
@CanIgnoreReturnValue
public static long copy(ReadableByteChannel from, WritableByteChannel to) throws IOException {
checkNotNull(from);
Expand Down Expand Up @@ -301,6 +301,7 @@ public static long exhaust(InputStream in) throws IOException {
* Returns a new {@link ByteArrayDataInput} instance to read from the {@code bytes} array from the
* beginning.
*/
@J2ktIncompatible
public static ByteArrayDataInput newDataInput(byte[] bytes) {
return newDataInput(new ByteArrayInputStream(bytes));
}
Expand All @@ -312,6 +313,7 @@ public static ByteArrayDataInput newDataInput(byte[] bytes) {
* @throws IndexOutOfBoundsException if {@code start} is negative or greater than the length of
* the array
*/
@J2ktIncompatible
public static ByteArrayDataInput newDataInput(byte[] bytes, int start) {
checkPositionIndex(start, bytes.length);
return newDataInput(new ByteArrayInputStream(bytes, start, bytes.length - start));
Expand All @@ -324,10 +326,12 @@ public static ByteArrayDataInput newDataInput(byte[] bytes, int start) {
*
* @since 17.0
*/
@J2ktIncompatible
public static ByteArrayDataInput newDataInput(ByteArrayInputStream byteArrayInputStream) {
return new ByteArrayDataInputStream(checkNotNull(byteArrayInputStream));
}

@J2ktIncompatible
private static class ByteArrayDataInputStream implements ByteArrayDataInput {
final DataInput input;

Expand Down Expand Up @@ -474,6 +478,7 @@ public String readUTF() {
}

/** Returns a new {@link ByteArrayDataOutput} instance with a default size. */
@J2ktIncompatible
public static ByteArrayDataOutput newDataOutput() {
return newDataOutput(new ByteArrayOutputStream());
}
Expand All @@ -484,6 +489,7 @@ public static ByteArrayDataOutput newDataOutput() {
*
* @throws IllegalArgumentException if {@code size} is negative
*/
@J2ktIncompatible
public static ByteArrayDataOutput newDataOutput(int size) {
// When called at high frequency, boxing size generates too much garbage,
// so avoid doing that if we can.
Expand All @@ -505,10 +511,12 @@ public static ByteArrayDataOutput newDataOutput(int size) {
*
* @since 17.0
*/
@J2ktIncompatible
public static ByteArrayDataOutput newDataOutput(ByteArrayOutputStream byteArrayOutputStream) {
return new ByteArrayDataOutputStream(checkNotNull(byteArrayOutputStream));
}

@J2ktIncompatible
private static class ByteArrayDataOutputStream implements ByteArrayDataOutput {

final DataOutput output;
Expand Down Expand Up @@ -693,10 +701,12 @@ public static OutputStream nullOutputStream() {
* @return a length-limited {@link InputStream}
* @since 14.0 (since 1.0 as com.google.common.io.LimitInputStream)
*/
@J2ktIncompatible
public static InputStream limit(InputStream in, long limit) {
return new LimitedInputStream(in, limit);
}

@J2ktIncompatible
private static final class LimitedInputStream extends FilterInputStream {

private long left;
Expand Down Expand Up @@ -879,6 +889,7 @@ private static long skipSafely(InputStream in, long n) throws IOException {
*/
@CanIgnoreReturnValue // some processors won't return a useful result
@ParametricNullness
@J2ktIncompatible
public static <T extends @Nullable Object> T readBytes(
InputStream input, ByteProcessor<T> processor) throws IOException {
checkNotNull(input);
Expand Down

0 comments on commit 5d7daae

Please sign in to comment.