Skip to content

Commit

Permalink
Remove a couple more obsolete workarounds for FilterOutputStream tr…
Browse files Browse the repository at this point in the history
…ouble.

See #1330.

I have the others taken care of in cl/687314611.

PiperOrigin-RevId: 688191691
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed Oct 21, 2024
1 parent 9911c83 commit 79c9e7a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
21 changes: 18 additions & 3 deletions android/guava/src/com/google/common/io/ByteSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ public OutputStream openBufferedStream() throws IOException {
public void write(byte[] bytes) throws IOException {
checkNotNull(bytes);

try (OutputStream out = openStream()) {
Closer closer = Closer.create();
try {
OutputStream out = closer.register(openStream());
out.write(bytes);
out.flush(); // https://github.com/google/guava/issues/1330
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}

Expand All @@ -115,8 +122,16 @@ public void write(byte[] bytes) throws IOException {
public long writeFrom(InputStream input) throws IOException {
checkNotNull(input);

try (OutputStream out = openStream()) {
return ByteStreams.copy(input, out);
Closer closer = Closer.create();
try {
OutputStream out = closer.register(openStream());
long written = ByteStreams.copy(input, out);
out.flush(); // https://github.com/google/guava/issues/1330
return written;
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}

Expand Down
9 changes: 8 additions & 1 deletion android/guava/src/com/google/common/io/CharSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ public Writer openBufferedStream() throws IOException {
public void write(CharSequence charSequence) throws IOException {
checkNotNull(charSequence);

try (Writer out = openStream()) {
Closer closer = Closer.create();
try {
Writer out = closer.register(openStream());
out.append(charSequence);
out.flush(); // https://github.com/google/guava/issues/1330
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}

Expand Down
21 changes: 18 additions & 3 deletions guava/src/com/google/common/io/ByteSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ public OutputStream openBufferedStream() throws IOException {
public void write(byte[] bytes) throws IOException {
checkNotNull(bytes);

try (OutputStream out = openStream()) {
Closer closer = Closer.create();
try {
OutputStream out = closer.register(openStream());
out.write(bytes);
out.flush(); // https://github.com/google/guava/issues/1330
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}

Expand All @@ -115,8 +122,16 @@ public void write(byte[] bytes) throws IOException {
public long writeFrom(InputStream input) throws IOException {
checkNotNull(input);

try (OutputStream out = openStream()) {
return ByteStreams.copy(input, out);
Closer closer = Closer.create();
try {
OutputStream out = closer.register(openStream());
long written = ByteStreams.copy(input, out);
out.flush(); // https://github.com/google/guava/issues/1330
return written;
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}

Expand Down
9 changes: 8 additions & 1 deletion guava/src/com/google/common/io/CharSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ public Writer openBufferedStream() throws IOException {
public void write(CharSequence charSequence) throws IOException {
checkNotNull(charSequence);

try (Writer out = openStream()) {
Closer closer = Closer.create();
try {
Writer out = closer.register(openStream());
out.append(charSequence);
out.flush(); // https://github.com/google/guava/issues/1330
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}

Expand Down

0 comments on commit 79c9e7a

Please sign in to comment.