what-the-bank/sources/com/google/common/io/ByteSink.java

76 lines
2.5 KiB
Java

package com.google.common.io;
import com.google.common.base.Preconditions;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
/* loaded from: classes2.dex */
public abstract class ByteSink {
public abstract OutputStream openStream() throws IOException;
public CharSink asCharSink(Charset charset) {
return new AsCharSink(charset);
}
public OutputStream openBufferedStream() throws IOException {
OutputStream openStream = openStream();
if (openStream instanceof BufferedOutputStream) {
return (BufferedOutputStream) openStream;
}
return new BufferedOutputStream(openStream);
}
public void write(byte[] bArr) throws IOException {
Preconditions.checkNotNull(bArr);
try {
OutputStream outputStream = (OutputStream) Closer.create().register(openStream());
outputStream.write(bArr);
outputStream.flush();
} finally {
}
}
public long writeFrom(InputStream inputStream) throws IOException {
Preconditions.checkNotNull(inputStream);
try {
OutputStream outputStream = (OutputStream) Closer.create().register(openStream());
long copy = ByteStreams.copy(inputStream, outputStream);
outputStream.flush();
return copy;
} finally {
}
}
/* loaded from: classes2.dex */
final class AsCharSink extends CharSink {
private final Charset charset;
final ByteSink this$0;
private AsCharSink(ByteSink byteSink, Charset charset) {
this.this$0 = byteSink;
this.charset = (Charset) Preconditions.checkNotNull(charset);
}
@Override // com.google.common.io.CharSink
public final Writer openStream() throws IOException {
return new OutputStreamWriter(this.this$0.openStream(), this.charset);
}
public final String toString() {
String obj = this.this$0.toString();
String valueOf = String.valueOf(this.charset);
StringBuilder sb = new StringBuilder(String.valueOf(obj).length() + 13 + String.valueOf(valueOf).length());
sb.append(obj);
sb.append(".asCharSink(");
sb.append(valueOf);
sb.append(")");
return sb.toString();
}
}
}