package kotlin.io; import androidx.exifinterface.media.ExifInterface; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import kotlin.Metadata; import kotlin.Unit; import kotlin.internal.PlatformImplementationsKt; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.InlineMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.sequences.Sequence; import kotlin.sequences.SequencesKt; import kotlin.text.Charsets; /* compiled from: ReadWrite.kt */ @Metadata(d1 = {"\u0000X\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0012\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\u001a\u0017\u0010\u0000\u001a\u00020\u0001*\u00020\u00022\b\b\u0002\u0010\u0003\u001a\u00020\u0004H\u0087\b\u001a\u0017\u0010\u0000\u001a\u00020\u0005*\u00020\u00062\b\b\u0002\u0010\u0003\u001a\u00020\u0004H\u0087\b\u001a\u001c\u0010\u0007\u001a\u00020\b*\u00020\u00022\u0006\u0010\t\u001a\u00020\u00062\b\b\u0002\u0010\u0003\u001a\u00020\u0004\u001a\u001e\u0010\n\u001a\u00020\u000b*\u00020\u00022\u0012\u0010\f\u001a\u000e\u0012\u0004\u0012\u00020\u000e\u0012\u0004\u0012\u00020\u000b0\r\u001a\u0010\u0010\u000f\u001a\b\u0012\u0004\u0012\u00020\u000e0\u0010*\u00020\u0001\u001a\n\u0010\u0011\u001a\u00020\u0012*\u00020\u0013\u001a\u0010\u0010\u0014\u001a\b\u0012\u0004\u0012\u00020\u000e0\u0015*\u00020\u0002\u001a\n\u0010\u0016\u001a\u00020\u000e*\u00020\u0002\u001a\u0017\u0010\u0016\u001a\u00020\u000e*\u00020\u00132\b\b\u0002\u0010\u0017\u001a\u00020\u0018H\u0087\b\u001a\r\u0010\u0019\u001a\u00020\u001a*\u00020\u000eH\u0087\b\u001a5\u0010\u001b\u001a\u0002H\u001c\"\u0004\b\u0000\u0010\u001c*\u00020\u00022\u0018\u0010\u001d\u001a\u0014\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u000e0\u0010\u0012\u0004\u0012\u0002H\u001c0\rH\u0086\bø\u0001\u0000¢\u0006\u0002\u0010\u001e\u0082\u0002\u0007\n\u0005\b\u009920\u0001¨\u0006\u001f"}, d2 = {"buffered", "Ljava/io/BufferedReader;", "Ljava/io/Reader;", "bufferSize", "", "Ljava/io/BufferedWriter;", "Ljava/io/Writer;", "copyTo", "", "out", "forEachLine", "", "action", "Lkotlin/Function1;", "", "lineSequence", "Lkotlin/sequences/Sequence;", "readBytes", "", "Ljava/net/URL;", "readLines", "", "readText", "charset", "Ljava/nio/charset/Charset;", "reader", "Ljava/io/StringReader;", "useLines", ExifInterface.GPS_DIRECTION_TRUE, "block", "(Ljava/io/Reader;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;", "kotlin-stdlib"}, k = 2, mv = {1, 9, 0}, xi = 48) /* loaded from: classes3.dex */ public final class TextStreamsKt { static /* synthetic */ BufferedReader buffered$default(Reader reader, int i, int i2, Object obj) { if ((i2 & 1) != 0) { i = 8192; } Intrinsics.checkNotNullParameter(reader, ""); return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, i); } private static final BufferedReader buffered(Reader reader, int i) { Intrinsics.checkNotNullParameter(reader, ""); return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, i); } static /* synthetic */ BufferedWriter buffered$default(Writer writer, int i, int i2, Object obj) { if ((i2 & 1) != 0) { i = 8192; } Intrinsics.checkNotNullParameter(writer, ""); return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer, i); } private static final BufferedWriter buffered(Writer writer, int i) { Intrinsics.checkNotNullParameter(writer, ""); return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer, i); } public static final List readLines(Reader reader) { Intrinsics.checkNotNullParameter(reader, ""); final ArrayList arrayList = new ArrayList(); forEachLine(reader, new Function1() { // from class: kotlin.io.TextStreamsKt$readLines$1 /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(1); } @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(String str) { invoke2(str); return Unit.INSTANCE; } /* renamed from: invoke, reason: avoid collision after fix types in other method */ public final void invoke2(String it) { Intrinsics.checkNotNullParameter(it, "it"); arrayList.add(it); } }); return arrayList; } public static final T useLines(Reader reader, Function1, ? extends T> block) { Intrinsics.checkNotNullParameter(reader, ""); Intrinsics.checkNotNullParameter(block, "block"); BufferedReader bufferedReader = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, 8192); try { T invoke = block.invoke(lineSequence(bufferedReader)); InlineMarker.finallyStart(1); if (PlatformImplementationsKt.apiVersionIsAtLeast(1, 1, 0)) { CloseableKt.closeFinally(bufferedReader, null); } else { bufferedReader.close(); } InlineMarker.finallyEnd(1); return invoke; } catch (Throwable th) { try { throw th; } catch (Throwable th2) { InlineMarker.finallyStart(1); if (PlatformImplementationsKt.apiVersionIsAtLeast(1, 1, 0)) { CloseableKt.closeFinally(bufferedReader, th); } else { try { bufferedReader.close(); } catch (Throwable unused) { } } InlineMarker.finallyEnd(1); throw th2; } } } private static final StringReader reader(String str) { Intrinsics.checkNotNullParameter(str, ""); return new StringReader(str); } public static final Sequence lineSequence(BufferedReader bufferedReader) { Intrinsics.checkNotNullParameter(bufferedReader, ""); return SequencesKt.constrainOnce(new LinesSequence(bufferedReader)); } public static final String readText(Reader reader) { Intrinsics.checkNotNullParameter(reader, ""); StringWriter stringWriter = new StringWriter(); copyTo$default(reader, stringWriter, 0, 2, null); String stringWriter2 = stringWriter.toString(); Intrinsics.checkNotNullExpressionValue(stringWriter2, "toString(...)"); return stringWriter2; } public static /* synthetic */ long copyTo$default(Reader reader, Writer writer, int i, int i2, Object obj) { if ((i2 & 2) != 0) { i = 8192; } return copyTo(reader, writer, i); } public static final long copyTo(Reader reader, Writer out, int i) { Intrinsics.checkNotNullParameter(reader, ""); Intrinsics.checkNotNullParameter(out, "out"); char[] cArr = new char[i]; int read = reader.read(cArr); long j = 0; while (read >= 0) { out.write(cArr, 0, read); j += read; read = reader.read(cArr); } return j; } private static final String readText(URL url, Charset charset) { Intrinsics.checkNotNullParameter(url, ""); Intrinsics.checkNotNullParameter(charset, "charset"); return new String(readBytes(url), charset); } static /* synthetic */ String readText$default(URL url, Charset charset, int i, Object obj) { if ((i & 1) != 0) { charset = Charsets.UTF_8; } Intrinsics.checkNotNullParameter(url, ""); Intrinsics.checkNotNullParameter(charset, "charset"); return new String(readBytes(url), charset); } public static final byte[] readBytes(URL url) { Intrinsics.checkNotNullParameter(url, ""); InputStream openStream = url.openStream(); try { InputStream inputStream = openStream; Intrinsics.checkNotNull(inputStream); byte[] readBytes = ByteStreamsKt.readBytes(inputStream); CloseableKt.closeFinally(openStream, null); return readBytes; } finally { } } public static final void forEachLine(Reader reader, Function1 action) { Intrinsics.checkNotNullParameter(reader, ""); Intrinsics.checkNotNullParameter(action, "action"); BufferedReader bufferedReader = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, 8192); try { Iterator it = lineSequence(bufferedReader).iterator(); while (it.hasNext()) { action.invoke(it.next()); } Unit unit = Unit.INSTANCE; CloseableKt.closeFinally(bufferedReader, null); } finally { } } }