Okio.java 7.3 KB
package okio;

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.InterruptedIOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import tv;
import tw;
import tx;
import ty;
import ua;

public final class Okio
{
  private static final Logger a = Logger.getLogger(Okio.class.getName());
  
  private static AsyncTimeout a(Socket paramSocket)
  {
    new AsyncTimeout()
    {
      protected final IOException newTimeoutException(IOException paramAnonymousIOException)
      {
        SocketTimeoutException localSocketTimeoutException = new SocketTimeoutException("timeout");
        if (paramAnonymousIOException != null) {
          localSocketTimeoutException.initCause(paramAnonymousIOException);
        }
        return localSocketTimeoutException;
      }
      
      protected final void timedOut()
      {
        try
        {
          this.a.close();
          return;
        }
        catch (Exception localException)
        {
          Okio.a().log(Level.WARNING, "Failed to close timed out socket " + this.a, localException);
          return;
        }
        catch (AssertionError localAssertionError)
        {
          if ((localAssertionError.getCause() != null) && (localAssertionError.getMessage() != null) && (localAssertionError.getMessage().contains("getsockname failed")))
          {
            Okio.a().log(Level.WARNING, "Failed to close timed out socket " + this.a, localAssertionError);
            return;
          }
          throw localAssertionError;
        }
      }
    };
  }
  
  private static Sink a(final OutputStream paramOutputStream, Timeout paramTimeout)
  {
    if (paramOutputStream == null) {
      throw new IllegalArgumentException("out == null");
    }
    if (paramTimeout == null) {
      throw new IllegalArgumentException("timeout == null");
    }
    new Sink()
    {
      public final void close()
        throws IOException
      {
        paramOutputStream.close();
      }
      
      public final void flush()
        throws IOException
      {
        paramOutputStream.flush();
      }
      
      public final Timeout timeout()
      {
        return this.a;
      }
      
      public final String toString()
      {
        return "sink(" + paramOutputStream + ")";
      }
      
      public final void write(Buffer paramAnonymousBuffer, long paramAnonymousLong)
        throws IOException
      {
        ua.a(paramAnonymousBuffer.b, 0L, paramAnonymousLong);
        while (paramAnonymousLong > 0L)
        {
          this.a.throwIfReached();
          tx localtx = paramAnonymousBuffer.a;
          int i = (int)Math.min(paramAnonymousLong, localtx.c - localtx.b);
          paramOutputStream.write(localtx.a, localtx.b, i);
          localtx.b += i;
          long l = paramAnonymousLong - i;
          paramAnonymousBuffer.b -= i;
          paramAnonymousLong = l;
          if (localtx.b == localtx.c)
          {
            paramAnonymousBuffer.a = localtx.a();
            ty.a(localtx);
            paramAnonymousLong = l;
          }
        }
      }
    };
  }
  
  private static Source a(final InputStream paramInputStream, Timeout paramTimeout)
  {
    if (paramInputStream == null) {
      throw new IllegalArgumentException("in == null");
    }
    if (paramTimeout == null) {
      throw new IllegalArgumentException("timeout == null");
    }
    new Source()
    {
      public final void close()
        throws IOException
      {
        paramInputStream.close();
      }
      
      public final long read(Buffer paramAnonymousBuffer, long paramAnonymousLong)
        throws IOException
      {
        if (paramAnonymousLong < 0L) {
          throw new IllegalArgumentException("byteCount < 0: " + paramAnonymousLong);
        }
        if (paramAnonymousLong == 0L) {
          return 0L;
        }
        this.a.throwIfReached();
        tx localtx = paramAnonymousBuffer.a(1);
        int i = (int)Math.min(paramAnonymousLong, 2048 - localtx.c);
        i = paramInputStream.read(localtx.a, localtx.c, i);
        if (i == -1) {
          return -1L;
        }
        localtx.c += i;
        paramAnonymousBuffer.b += i;
        return i;
      }
      
      public final Timeout timeout()
      {
        return this.a;
      }
      
      public final String toString()
      {
        return "source(" + paramInputStream + ")";
      }
    };
  }
  
  public static Sink appendingSink(File paramFile)
    throws FileNotFoundException
  {
    if (paramFile == null) {
      throw new IllegalArgumentException("file == null");
    }
    return sink(new FileOutputStream(paramFile, true));
  }
  
  public static BufferedSink buffer(Sink paramSink)
  {
    if (paramSink == null) {
      throw new IllegalArgumentException("sink == null");
    }
    return new tv(paramSink);
  }
  
  public static BufferedSource buffer(Source paramSource)
  {
    if (paramSource == null) {
      throw new IllegalArgumentException("source == null");
    }
    return new tw(paramSource);
  }
  
  public static Sink sink(File paramFile)
    throws FileNotFoundException
  {
    if (paramFile == null) {
      throw new IllegalArgumentException("file == null");
    }
    return sink(new FileOutputStream(paramFile));
  }
  
  public static Sink sink(OutputStream paramOutputStream)
  {
    return a(paramOutputStream, new Timeout());
  }
  
  public static Sink sink(Socket paramSocket)
    throws IOException
  {
    if (paramSocket == null) {
      throw new IllegalArgumentException("socket == null");
    }
    AsyncTimeout localAsyncTimeout = a(paramSocket);
    return localAsyncTimeout.sink(a(paramSocket.getOutputStream(), localAsyncTimeout));
  }
  
  @IgnoreJRERequirement
  public static Sink sink(Path paramPath, OpenOption... paramVarArgs)
    throws IOException
  {
    if (paramPath == null) {
      throw new IllegalArgumentException("path == null");
    }
    return sink(Files.newOutputStream(paramPath, paramVarArgs));
  }
  
  public static Source source(File paramFile)
    throws FileNotFoundException
  {
    if (paramFile == null) {
      throw new IllegalArgumentException("file == null");
    }
    return source(new FileInputStream(paramFile));
  }
  
  public static Source source(InputStream paramInputStream)
  {
    return a(paramInputStream, new Timeout());
  }
  
  public static Source source(Socket paramSocket)
    throws IOException
  {
    if (paramSocket == null) {
      throw new IllegalArgumentException("socket == null");
    }
    AsyncTimeout localAsyncTimeout = a(paramSocket);
    return localAsyncTimeout.source(a(paramSocket.getInputStream(), localAsyncTimeout));
  }
  
  @IgnoreJRERequirement
  public static Source source(Path paramPath, OpenOption... paramVarArgs)
    throws IOException
  {
    if (paramPath == null) {
      throw new IllegalArgumentException("path == null");
    }
    return source(Files.newInputStream(paramPath, paramVarArgs));
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/okio/Okio.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */