mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-26 17:12:31 -06:00
212 lines
6.4 KiB
Java
212 lines
6.4 KiB
Java
|
package com.google.common.io;
|
||
|
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import java.io.EOFException;
|
||
|
import java.io.IOException;
|
||
|
import java.io.Reader;
|
||
|
import java.io.Writer;
|
||
|
import java.nio.CharBuffer;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
import javax.annotation.CheckForNull;
|
||
|
|
||
|
@ElementTypesAreNonnullByDefault
|
||
|
/* loaded from: classes3.dex */
|
||
|
public final class CharStreams {
|
||
|
private static final int DEFAULT_BUF_SIZE = 2048;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static CharBuffer createBuffer() {
|
||
|
return CharBuffer.allocate(2048);
|
||
|
}
|
||
|
|
||
|
private CharStreams() {
|
||
|
}
|
||
|
|
||
|
public static long copy(Readable readable, Appendable appendable) throws IOException {
|
||
|
if (readable instanceof Reader) {
|
||
|
if (appendable instanceof StringBuilder) {
|
||
|
return copyReaderToBuilder((Reader) readable, (StringBuilder) appendable);
|
||
|
}
|
||
|
return copyReaderToWriter((Reader) readable, asWriter(appendable));
|
||
|
}
|
||
|
Preconditions.checkNotNull(readable);
|
||
|
Preconditions.checkNotNull(appendable);
|
||
|
CharBuffer createBuffer = createBuffer();
|
||
|
long j = 0;
|
||
|
while (readable.read(createBuffer) != -1) {
|
||
|
Java8Compatibility.flip(createBuffer);
|
||
|
appendable.append(createBuffer);
|
||
|
j += createBuffer.remaining();
|
||
|
Java8Compatibility.clear(createBuffer);
|
||
|
}
|
||
|
return j;
|
||
|
}
|
||
|
|
||
|
static long copyReaderToBuilder(Reader reader, StringBuilder sb) throws IOException {
|
||
|
Preconditions.checkNotNull(reader);
|
||
|
Preconditions.checkNotNull(sb);
|
||
|
char[] cArr = new char[2048];
|
||
|
long j = 0;
|
||
|
while (true) {
|
||
|
int read = reader.read(cArr);
|
||
|
if (read == -1) {
|
||
|
return j;
|
||
|
}
|
||
|
sb.append(cArr, 0, read);
|
||
|
j += read;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static long copyReaderToWriter(Reader reader, Writer writer) throws IOException {
|
||
|
Preconditions.checkNotNull(reader);
|
||
|
Preconditions.checkNotNull(writer);
|
||
|
char[] cArr = new char[2048];
|
||
|
long j = 0;
|
||
|
while (true) {
|
||
|
int read = reader.read(cArr);
|
||
|
if (read == -1) {
|
||
|
return j;
|
||
|
}
|
||
|
writer.write(cArr, 0, read);
|
||
|
j += read;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static String toString(Readable readable) throws IOException {
|
||
|
return toStringBuilder(readable).toString();
|
||
|
}
|
||
|
|
||
|
private static StringBuilder toStringBuilder(Readable readable) throws IOException {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
if (readable instanceof Reader) {
|
||
|
copyReaderToBuilder((Reader) readable, sb);
|
||
|
} else {
|
||
|
copy(readable, sb);
|
||
|
}
|
||
|
return sb;
|
||
|
}
|
||
|
|
||
|
public static List<String> readLines(Readable readable) throws IOException {
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
LineReader lineReader = new LineReader(readable);
|
||
|
while (true) {
|
||
|
String readLine = lineReader.readLine();
|
||
|
if (readLine == null) {
|
||
|
return arrayList;
|
||
|
}
|
||
|
arrayList.add(readLine);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@ParametricNullness
|
||
|
public static <T> T readLines(Readable readable, LineProcessor<T> lineProcessor) throws IOException {
|
||
|
String readLine;
|
||
|
Preconditions.checkNotNull(readable);
|
||
|
Preconditions.checkNotNull(lineProcessor);
|
||
|
LineReader lineReader = new LineReader(readable);
|
||
|
do {
|
||
|
readLine = lineReader.readLine();
|
||
|
if (readLine == null) {
|
||
|
break;
|
||
|
}
|
||
|
} while (lineProcessor.processLine(readLine));
|
||
|
return lineProcessor.getResult();
|
||
|
}
|
||
|
|
||
|
public static long exhaust(Readable readable) throws IOException {
|
||
|
CharBuffer createBuffer = createBuffer();
|
||
|
long j = 0;
|
||
|
while (true) {
|
||
|
long read = readable.read(createBuffer);
|
||
|
if (read == -1) {
|
||
|
return j;
|
||
|
}
|
||
|
j += read;
|
||
|
Java8Compatibility.clear(createBuffer);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void skipFully(Reader reader, long j) throws IOException {
|
||
|
Preconditions.checkNotNull(reader);
|
||
|
while (j > 0) {
|
||
|
long skip = reader.skip(j);
|
||
|
if (skip == 0) {
|
||
|
throw new EOFException();
|
||
|
}
|
||
|
j -= skip;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static Writer nullWriter() {
|
||
|
return NullWriter.INSTANCE;
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes3.dex */
|
||
|
private static final class NullWriter extends Writer {
|
||
|
private static final NullWriter INSTANCE = new NullWriter();
|
||
|
|
||
|
@Override // java.io.Writer, java.lang.Appendable
|
||
|
public Writer append(char c) {
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer, java.lang.Appendable
|
||
|
public Writer append(@CheckForNull CharSequence charSequence) {
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer, java.io.Closeable, java.lang.AutoCloseable
|
||
|
public void close() {
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer, java.io.Flushable
|
||
|
public void flush() {
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
return "CharStreams.nullWriter()";
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer
|
||
|
public void write(int i) {
|
||
|
}
|
||
|
|
||
|
private NullWriter() {
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer
|
||
|
public void write(char[] cArr) {
|
||
|
Preconditions.checkNotNull(cArr);
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer
|
||
|
public void write(char[] cArr, int i, int i2) {
|
||
|
Preconditions.checkPositionIndexes(i, i2 + i, cArr.length);
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer
|
||
|
public void write(String str) {
|
||
|
Preconditions.checkNotNull(str);
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer
|
||
|
public void write(String str, int i, int i2) {
|
||
|
Preconditions.checkPositionIndexes(i, i2 + i, str.length());
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Writer, java.lang.Appendable
|
||
|
public Writer append(@CheckForNull CharSequence charSequence, int i, int i2) {
|
||
|
Preconditions.checkPositionIndexes(i, i2, charSequence == null ? 4 : charSequence.length());
|
||
|
return this;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static Writer asWriter(Appendable appendable) {
|
||
|
if (appendable instanceof Writer) {
|
||
|
return (Writer) appendable;
|
||
|
}
|
||
|
return new AppendableWriter(appendable);
|
||
|
}
|
||
|
}
|