l.java 源代码
package s3;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
public final class l {
static final Logger f26157a = Logger.getLogger(l.class.getName());
public final class a implements r {
final t f26158q;
final OutputStream f26159r;
a(t tVar, OutputStream outputStream) {
this.f26158q = tVar;
this.f26159r = outputStream;
}
@Override
public void a(s3.c cVar, long j6) throws IOException {
u.b(cVar.f26138r, 0L, j6);
while (j6 > 0) {
this.f26158q.f();
o oVar = cVar.f26137q;
int min = (int) Math.min(j6, oVar.f26172c - oVar.f26171b);
this.f26159r.write(oVar.f26170a, oVar.f26171b, min);
int i6 = oVar.f26171b + min;
oVar.f26171b = i6;
long j7 = min;
j6 -= j7;
cVar.f26138r -= j7;
if (i6 == oVar.f26172c) {
cVar.f26137q = oVar.b();
p.a(oVar);
}
}
}
@Override
public void close() throws IOException {
this.f26159r.close();
}
@Override
public void flush() throws IOException {
this.f26159r.flush();
}
@Override
public t timeout() {
return this.f26158q;
}
public String toString() {
return "sink(" + this.f26159r + ")";
}
}
public final class b implements s {
final t f26160q;
final InputStream f26161r;
b(t tVar, InputStream inputStream) {
this.f26160q = tVar;
this.f26161r = inputStream;
}
@Override
public long b(s3.c cVar, long j6) throws IOException {
if (j6 >= 0) {
if (j6 == 0) {
return 0L;
}
try {
this.f26160q.f();
o z6 = cVar.z(1);
int read = this.f26161r.read(z6.f26170a, z6.f26172c, (int) Math.min(j6, 8192 - z6.f26172c));
if (read == -1) {
return -1L;
}
z6.f26172c += read;
long j7 = read;
cVar.f26138r += j7;
return j7;
} catch (AssertionError e6) {
if (l.e(e6)) {
throw new IOException(e6);
}
throw e6;
}
}
throw new IllegalArgumentException("byteCount < 0: " + j6);
}
@Override
public void close() throws IOException {
this.f26161r.close();
}
@Override
public t timeout() {
return this.f26160q;
}
public String toString() {
return "source(" + this.f26161r + ")";
}
}
final class c implements r {
c() {
}
@Override
public void a(s3.c cVar, long j6) throws IOException {
cVar.skip(j6);
}
@Override
public void close() throws IOException {
}
@Override
public void flush() throws IOException {
}
@Override
public t timeout() {
return t.f26181d;
}
}
public final class d extends s3.a {
final Socket f26162k;
d(Socket socket) {
this.f26162k = socket;
}
@Override
protected IOException o(@Nullable IOException iOException) {
SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout");
if (iOException != null) {
socketTimeoutException.initCause(iOException);
}
return socketTimeoutException;
}
@Override
protected void t() {
try {
this.f26162k.close();
} catch (AssertionError e6) {
if (l.e(e6)) {
l.f26157a.log(Level.WARNING, "Failed to close timed out socket " + this.f26162k, (Throwable) e6);
return;
}
throw e6;
} catch (Exception e7) {
l.f26157a.log(Level.WARNING, "Failed to close timed out socket " + this.f26162k, (Throwable) e7);
}
}
}
private l() {
}
public static r a(File file) throws FileNotFoundException {
if (file != null) {
return g(new FileOutputStream(file, true));
}
throw new IllegalArgumentException("file == null");
}
public static r b() {
return new c();
}
public static s3.d c(r rVar) {
return new m(rVar);
}
public static e d(s sVar) {
return new n(sVar);
}
static boolean e(AssertionError assertionError) {
if (assertionError.getCause() != null && assertionError.getMessage() != null && assertionError.getMessage().contains("getsockname failed")) {
return true;
}
return false;
}
public static r f(File file) throws FileNotFoundException {
if (file != null) {
return g(new FileOutputStream(file));
}
throw new IllegalArgumentException("file == null");
}
public static r g(OutputStream outputStream) {
return h(outputStream, new t());
}
private static r h(OutputStream outputStream, t tVar) {
if (outputStream != null) {
if (tVar != null) {
return new a(tVar, outputStream);
}
throw new IllegalArgumentException("timeout == null");
}
throw new IllegalArgumentException("out == null");
}
public static r i(Socket socket) throws IOException {
if (socket != null) {
if (socket.getOutputStream() != null) {
s3.a n6 = n(socket);
return n6.r(h(socket.getOutputStream(), n6));
}
throw new IOException("socket's output stream == null");
}
throw new IllegalArgumentException("socket == null");
}
public static s j(File file) throws FileNotFoundException {
if (file != null) {
return k(new FileInputStream(file));
}
throw new IllegalArgumentException("file == null");
}
public static s k(InputStream inputStream) {
return l(inputStream, new t());
}
private static s l(InputStream inputStream, t tVar) {
if (inputStream != null) {
if (tVar != null) {
return new b(tVar, inputStream);
}
throw new IllegalArgumentException("timeout == null");
}
throw new IllegalArgumentException("in == null");
}
public static s m(Socket socket) throws IOException {
if (socket != null) {
if (socket.getInputStream() != null) {
s3.a n6 = n(socket);
return n6.s(l(socket.getInputStream(), n6));
}
throw new IOException("socket's input stream == null");
}
throw new IllegalArgumentException("socket == null");
}
private static s3.a n(Socket socket) {
return new d(socket);
}
}