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

103 lines
3.1 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.io;
import com.google.common.base.Preconditions;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
/* loaded from: classes2.dex */
class AppendableWriter extends Writer {
private boolean closed;
private final Appendable target;
@Override // java.io.Writer, java.lang.Appendable
public /* bridge */ /* synthetic */ Appendable append(char c) throws IOException {
return append(c);
}
@Override // java.io.Writer, java.lang.Appendable
public /* bridge */ /* synthetic */ Appendable append(CharSequence charSequence) throws IOException {
return append(charSequence);
}
@Override // java.io.Writer, java.lang.Appendable
public /* bridge */ /* synthetic */ Appendable append(CharSequence charSequence, int i, int i2) throws IOException {
return append(charSequence, i, i2);
}
/* JADX INFO: Access modifiers changed from: package-private */
public AppendableWriter(Appendable appendable) {
this.target = (Appendable) Preconditions.checkNotNull(appendable);
}
@Override // java.io.Writer
public void write(char[] cArr, int i, int i2) throws IOException {
checkNotClosed();
this.target.append(new String(cArr, i, i2));
}
@Override // java.io.Writer
public void write(int i) throws IOException {
checkNotClosed();
this.target.append((char) i);
}
@Override // java.io.Writer
public void write(String str) throws IOException {
checkNotClosed();
this.target.append(str);
}
@Override // java.io.Writer
public void write(String str, int i, int i2) throws IOException {
checkNotClosed();
this.target.append(str, i, i2 + i);
}
@Override // java.io.Writer, java.io.Flushable
public void flush() throws IOException {
checkNotClosed();
Appendable appendable = this.target;
if (appendable instanceof Flushable) {
((Flushable) appendable).flush();
}
}
@Override // java.io.Writer, java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
this.closed = true;
Appendable appendable = this.target;
if (appendable instanceof Closeable) {
((Closeable) appendable).close();
}
}
@Override // java.io.Writer, java.lang.Appendable
public Writer append(char c) throws IOException {
checkNotClosed();
this.target.append(c);
return this;
}
@Override // java.io.Writer, java.lang.Appendable
public Writer append(CharSequence charSequence) throws IOException {
checkNotClosed();
this.target.append(charSequence);
return this;
}
@Override // java.io.Writer, java.lang.Appendable
public Writer append(CharSequence charSequence, int i, int i2) throws IOException {
checkNotClosed();
this.target.append(charSequence, i, i2);
return this;
}
private void checkNotClosed() throws IOException {
if (this.closed) {
throw new IOException("Cannot write to a closed writer.");
}
}
}