Remove a couple more obsolete workarounds for FilterOutputStream trouble.

See https://github.com/google/guava/issues/1330.

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

PiperOrigin-RevId: 688191691
This commit is contained in:
Google Java Core Libraries 2024-10-21 10:41:28 -07:00 committed by Google Java Core Libraries
parent 9911c8347f
commit 79c9e7a36c
4 changed files with 52 additions and 8 deletions

View File

@ -99,8 +99,15 @@ public abstract class ByteSink {
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();
}
}
@ -115,8 +122,16 @@ public abstract class ByteSink {
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();
}
}

View File

@ -92,8 +92,15 @@ public abstract class CharSink {
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();
}
}

View File

@ -99,8 +99,15 @@ public abstract class ByteSink {
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();
}
}
@ -115,8 +122,16 @@ public abstract class ByteSink {
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();
}
}

View File

@ -94,8 +94,15 @@ public abstract class CharSink {
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();
}
}