com.crashlytics.tools.android_2.1.0

;
  private CoderResult lastCoderResult;
  private boolean endOfInput;
  
  public ReaderInputStream(Reader reader, CharsetEncoder encoder)
  {
    this(reader, encoder, 1024);
  }
  
  public ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize)
  {
    this.reader = reader;
    this.encoder = encoder;
    encoderIn = CharBuffer.allocate(bufferSize);
    encoderIn.flip();
    encoderOut = ByteBuffer.allocate(128);
    encoderOut.flip();
  }
  
  public ReaderInputStream(Reader reader, Charset charset, int bufferSize)
  {
    this(reader, charset.newEncoder().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE), bufferSize);
  }
  
  public ReaderInputStream(Reader reader, Charset charset)
  {
    this(reader, charset, 1024);
  }
  
  public ReaderInputStream(Reader reader, String charsetName, int bufferSize)
  {
    this(reader, Charset.forName(charsetName), bufferSize);
  }
  
  public ReaderInputStream(Reader reader, String charsetName)
  {
    this(reader, charsetName, 1024);
  }
  
  public ReaderInputStream(Reader reader)
  {
    this(reader, Charset.defaultCharset());
  }
  
  private void fillBuffer()
    throws IOException
  {
    if ((!endOfInput) && ((lastCoderResult == null) || (lastCoderResult.isUnderflow())))
    {
      encoderIn.compact();
      int position = encoderIn.position();
      
      int c = reader.read(encoderIn.array(), position, encoderIn.remaining());
      if (c == -1) {
        endOfInput = true;
      } else {
        encoderIn.position(position + c);
      }
      encoderIn.flip();
    }
    encoderOut.compact();
    lastCoderResult = encoder.encode(encoderIn, encoderOut, endOfInput);
    encoderOut.flip();
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    if (b == null) {
      throw new NullPointerException("Byte array must not be null");
    }
    if ((len < 0) || (off < 0) || (off + len > b.length)) {
      throw new IndexOutOfBoundsException("Array Size=" + b.length + ", offset=" + off + ", length=" + len);
    }
    int read = 0;
    if (len == 0) {
      return 0;
    }
    while (len > 0) {
      if (encoderOut.hasRemaining())
      {
        int c = Math.min(encoderOut.remaining(), len);
        encoderOut.get(b, off, c);
        off += c;
        len -= c;
        read += c;
      }
      else
      {
        fillBuffer();
        if ((endOfInput) && (!encoderOut.hasRemaining())) {
          break;
        }
      }
    }
    return (read == 0) && (endOfInput) ? -1 : read;
  }
  
  public int read(byte[] b)
    throws IOException
  {
    return read(b, 0, b.length);
  }
  
  public int read()
    throws IOException
  {
    do
    {
      if (encoderOut.hasRemaining()) {
        return encoderOut.get() & 0xFF;
      }
      fillBuffer();
    } while ((!endOfInput) || (encoderOut.hasRemaining()));
    return -1;
  }
  
  public void close()
    throws IOException
  {
    reader.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.ReaderInputStream
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

class ReversedLinesFileReader$1 {}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.ReversedLinesFileReader.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.IOException;
import java.io.RandomAccessFile;

class ReversedLinesFileReader$FilePart
{
  private final long no;
  private final byte[] data;
  private byte[] leftOver;
  private int currentLastBytePos;
  
  private ReversedLinesFileReader$FilePart(ReversedLinesFileReader arg1, long no, int length, byte[] leftOverOfLastFilePart)
    throws IOException
  {
    this.no = no;
    int dataLength = length + (leftOverOfLastFilePart != null ? leftOverOfLastFilePart.length : 0);
    data = new byte[dataLength];
    long off = (no - 1L) * ReversedLinesFileReader.access$300(???);
    if (no > 0L)
    {
      ReversedLinesFileReader.access$400(???).seek(off);
      int countRead = ReversedLinesFileReader.access$400(???).read(data, 0, length);
      if (countRead != length) {
        throw new IllegalStateException("Count of requested bytes and actually read bytes don't match");
      }
    }
    if (leftOverOfLastFilePart != null) {
      System.arraycopy(leftOverOfLastFilePart, 0, data, length, leftOverOfLastFilePart.length);
    }
    currentLastBytePos = (data.length - 1);
    leftOver = null;
  }
  
  private FilePart rollOver()
    throws IOException
  {
    if (currentLastBytePos > -1) {
      throw new IllegalStateException("Current currentLastCharPos unexpectedly positive... last readLine() should have returned something! currentLastCharPos=" + currentLastBytePos);
    }
    if (no > 1L) {
      return new FilePart(this$0, no - 1L, ReversedLinesFileReader.access$300(this$0), leftOver);
    }
    if (leftOver != null) {
      throw new IllegalStateException("Unexpected leftover of the last block: leftOverOfThisFilePart=" + new String(leftOver, ReversedLinesFileReader.access$500(this$0)));
    }
    return null;
  }
  
  private String readLine()
    throws IOException
  {
    String line = null;
    
    boolean isLastFilePart = no == 1L;
    
    int i = currentLastBytePos;
    while (i > -1) {
      if ((!isLastFilePart) && (i < ReversedLinesFileReader.access$600(this$0)))
      {
        createLeftOver();
      }
      else
      {
        int newLineMatchByteCount;
        if ((newLineMatchByteCount = getNewLineMatchByteCount(data, i)) > 0)
        {
          int lineStart = i + 1;
          int lineLengthBytes = currentLastBytePos - lineStart + 1;
          if (lineLengthBytes < 0) {
            throw new IllegalStateException("Unexpected negative line length=" + lineLengthBytes);
          }
          byte[] lineData = new byte[lineLengthBytes];
          System.arraycopy(data, lineStart, lineData, 0, lineLengthBytes);
          
          line = new String(lineData, ReversedLinesFileReader.access$500(this$0));
          
          currentLastBytePos = (i - newLineMatchByteCount);
        }
        else
        {
          i -= ReversedLinesFileReader.access$700(this$0);
          if (i < 0) {
            createLeftOver();
          }
        }
      }
    }
    if ((isLastFilePart) && (leftOver != null))
    {
      line = new String(leftOver, ReversedLinesFileReader.access$500(this$0));
      leftOver = null;
    }
    return line;
  }
  
  private void createLeftOver()
  {
    int lineLengthBytes = currentLastBytePos + 1;
    if (lineLengthBytes > 0)
    {
      leftOver = new byte[lineLengthBytes];
      System.arraycopy(data, 0, leftOver, 0, lineLengthBytes);
    }
    else
    {
      leftOver = null;
    }
    currentLastBytePos = -1;
  }
  
  private int getNewLineMatchByteCount(byte[] data, int i)
  {
    for (byte[] newLineSequence : ReversedLinesFileReader.access$800(this$0))
    {
      boolean match = true;
      for (int j = newLineSequence.length - 1; j >= 0; j--)
      {
        int k = i + j - (newLineSequence.length - 1);
        match &= ((k >= 0) && (data[k] == newLineSequence[j]));
      }
      if (match) {
        return newLineSequence.length;
      }
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.ReversedLinesFileReader.FilePart
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import org.apache.commons.io.Charsets;

public class ReversedLinesFileReader
  implements Closeable
{
  private final int blockSize;
  private final Charset encoding;
  private final RandomAccessFile randomAccessFile;
  private final long totalByteLength;
  private final long totalBlockCount;
  private final byte[][] newLineSequences;
  private final int avoidNewlineSplitBufferSize;
  private final int byteDecrement;
  private FilePart currentFilePart;
  private boolean trailingNewlineOfFileSkipped = false;
  
  public ReversedLinesFileReader(File file)
    throws IOException
  {
    this(file, 4096, Charset.defaultCharset().toString());
  }
  
  public ReversedLinesFileReader(File file, int blockSize, Charset encoding)
    throws IOException
  {
    this.blockSize = blockSize;
    this.encoding = encoding;
    
    randomAccessFile = new RandomAccessFile(file, "r");
    totalByteLength = randomAccessFile.length();
    int lastBlockLength = (int)(totalByteLength % blockSize);
    if (lastBlockLength > 0)
    {
      totalBlockCount = (totalByteLength / blockSize + 1L);
    }
    else
    {
      totalBlockCount = (totalByteLength / blockSize);
      if (totalByteLength > 0L) {
        lastBlockLength = blockSize;
      }
    }
    currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null, null);
    
    Charset charset = Charsets.toCharset(encoding);
    CharsetEncoder charsetEncoder = charset.newEncoder();
    float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
    if (maxBytesPerChar == 1.0F)
    {
      byteDecrement = 1;
    }
    else if (charset == Charset.forName("UTF-8"))
    {
      byteDecrement = 1;
    }
    else if (charset == Charset.forName("Shift_JIS"))
    {
      byteDecrement = 1;
    }
    else if ((charset == Charset.forName("UTF-16BE")) || (charset == Charset.forName("UTF-16LE")))
    {
      byteDecrement = 2;
    }
    else
    {
      if (charset == Charset.forName("UTF-16")) {
        throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or UTF-16LE)");
      }
      throw new UnsupportedEncodingException("Encoding " + encoding + " is not supported yet (feel free to submit a patch)");
    }
    newLineSequences = new byte[][] { "\r\n".getBytes(encoding), "\n".getBytes(encoding), "\r".getBytes(encoding) };
    
    avoidNewlineSplitBufferSize = newLineSequences[0].length;
  }
  
  public ReversedLinesFileReader(File file, int blockSize, String encoding)
    throws IOException
  {
    this(file, blockSize, Charsets.toCharset(encoding));
  }
  
  public String readLine()
    throws IOException
  {
    String line = currentFilePart.readLine();
    while (line == null)
    {
      currentFilePart = currentFilePart.rollOver();
      if (currentFilePart == null) {
        break;
      }
      line = currentFilePart.readLine();
    }
    if (("".equals(line)) && (!trailingNewlineOfFileSkipped))
    {
      trailingNewlineOfFileSkipped = true;
      line = readLine();
    }
    return line;
  }
  
  public void close()
    throws IOException
  {
    randomAccessFile.close();
  }
  
  private class FilePart
  {
    private final long no;
    private final byte[] data;
    private byte[] leftOver;
    private int currentLastBytePos;
    
    private FilePart(long no, int length, byte[] leftOverOfLastFilePart)
      throws IOException
    {
      this.no = no;
      int dataLength = length + (leftOverOfLastFilePart != null ? leftOverOfLastFilePart.length : 0);
      data = new byte[dataLength];
      long off = (no - 1L) * blockSize;
      if (no > 0L)
      {
        randomAccessFile.seek(off);
        int countRead = randomAccessFile.read(data, 0, length);
        if (countRead != length) {
          throw new IllegalStateException("Count of requested bytes and actually read bytes don't match");
        }
      }
      if (leftOverOfLastFilePart != null) {
        System.arraycopy(leftOverOfLastFilePart, 0, data, length, leftOverOfLastFilePart.length);
      }
      currentLastBytePos = (data.length - 1);
      leftOver = null;
    }
    
    private FilePart rollOver()
      throws IOException
    {
      if (currentLastBytePos > -1) {
        throw new IllegalStateException("Current currentLastCharPos unexpectedly positive... last readLine() should have returned something! currentLastCharPos=" + currentLastBytePos);
      }
      if (no > 1L) {
        return new FilePart(ReversedLinesFileReader.this, no - 1L, blockSize, leftOver);
      }
      if (leftOver != null) {
        throw new IllegalStateException("Unexpected leftover of the last block: leftOverOfThisFilePart=" + new String(leftOver, encoding));
      }
      return null;
    }
    
    private String readLine()
      throws IOException
    {
      String line = null;
      
      boolean isLastFilePart = no == 1L;
      
      int i = currentLastBytePos;
      while (i > -1) {
        if ((!isLastFilePart) && (i < avoidNewlineSplitBufferSize))
        {
          createLeftOver();
        }
        else
        {
          int newLineMatchByteCount;
          if ((newLineMatchByteCount = getNewLineMatchByteCount(data, i)) > 0)
          {
            int lineStart = i + 1;
            int lineLengthBytes = currentLastBytePos - lineStart + 1;
            if (lineLengthBytes < 0) {
              throw new IllegalStateException("Unexpected negative line length=" + lineLengthBytes);
            }
            byte[] lineData = new byte[lineLengthBytes];
            System.arraycopy(data, lineStart, lineData, 0, lineLengthBytes);
            
            line = new String(lineData, encoding);
            
            currentLastBytePos = (i - newLineMatchByteCount);
          }
          else
          {
            i -= byteDecrement;
            if (i < 0) {
              createLeftOver();
            }
          }
        }
      }
      if ((isLastFilePart) && (leftOver != null))
      {
        line = new String(leftOver, encoding);
        leftOver = null;
      }
      return line;
    }
    
    private void createLeftOver()
    {
      int lineLengthBytes = currentLastBytePos + 1;
      if (lineLengthBytes > 0)
      {
        leftOver = new byte[lineLengthBytes];
        System.arraycopy(data, 0, leftOver, 0, lineLengthBytes);
      }
      else
      {
        leftOver = null;
      }
      currentLastBytePos = -1;
    }
    
    private int getNewLineMatchByteCount(byte[] data, int i)
    {
      for (byte[] newLineSequence : newLineSequences)
      {
        boolean match = true;
        for (int j = newLineSequence.length - 1; j >= 0; j--)
        {
          int k = i + j - (newLineSequence.length - 1);
          match &= ((k >= 0) && (data[k] == newLineSequence[j]));
        }
        if (match) {
          return newLineSequence.length;
        }
      }
      return 0;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.ReversedLinesFileReader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.DataInput;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.EndianUtils;

public class SwappedDataInputStream
  extends ProxyInputStream
  implements DataInput
{
  public SwappedDataInputStream(InputStream input)
  {
    super(input);
  }
  
  public boolean readBoolean()
    throws IOException, EOFException
  {
    return 0 != readByte();
  }
  
  public byte readByte()
    throws IOException, EOFException
  {
    return (byte)in.read();
  }
  
  public char readChar()
    throws IOException, EOFException
  {
    return (char)readShort();
  }
  
  public double readDouble()
    throws IOException, EOFException
  {
    return EndianUtils.readSwappedDouble(in);
  }
  
  public float readFloat()
    throws IOException, EOFException
  {
    return EndianUtils.readSwappedFloat(in);
  }
  
  public void readFully(byte[] data)
    throws IOException, EOFException
  {
    readFully(data, 0, data.length);
  }
  
  public void readFully(byte[] data, int offset, int length)
    throws IOException, EOFException
  {
    int remaining = length;
    while (remaining > 0)
    {
      int location = offset + length - remaining;
      int count = read(data, location, remaining);
      if (-1 == count) {
        throw new EOFException();
      }
      remaining -= count;
    }
  }
  
  public int readInt()
    throws IOException, EOFException
  {
    return EndianUtils.readSwappedInteger(in);
  }
  
  public String readLine()
    throws IOException, EOFException
  {
    throw new UnsupportedOperationException("Operation not supported: readLine()");
  }
  
  public long readLong()
    throws IOException, EOFException
  {
    return EndianUtils.readSwappedLong(in);
  }
  
  public short readShort()
    throws IOException, EOFException
  {
    return EndianUtils.readSwappedShort(in);
  }
  
  public int readUnsignedByte()
    throws IOException, EOFException
  {
    return in.read();
  }
  
  public int readUnsignedShort()
    throws IOException, EOFException
  {
    return EndianUtils.readSwappedUnsignedShort(in);
  }
  
  public String readUTF()
    throws IOException, EOFException
  {
    throw new UnsupportedOperationException("Operation not supported: readUTF()");
  }
  
  public int skipBytes(int count)
    throws IOException, EOFException
  {
    return (int)in.skip(count);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.SwappedDataInputStream
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.UUID;
import org.apache.commons.io.TaggedIOException;

public class TaggedInputStream
  extends ProxyInputStream
{
  private final Serializable tag = UUID.randomUUID();
  
  public TaggedInputStream(InputStream proxy)
  {
    super(proxy);
  }
  
  public boolean isCauseOf(Throwable exception)
  {
    return TaggedIOException.isTaggedWith(exception, tag);
  }
  
  public void throwIfCauseOf(Throwable throwable)
    throws IOException
  {
    TaggedIOException.throwCauseIfTaggedWith(throwable, tag);
  }
  
  protected void handleIOException(IOException e)
    throws IOException
  {
    throw new TaggedIOException(e, tag);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.TaggedInputStream
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

public class Tailer
  implements Runnable
{
  private static final int DEFAULT_DELAY_MILLIS = 1000;
  private static final String RAF_MODE = "r";
  private static final int DEFAULT_BUFSIZE = 4096;
  private final byte[] inbuf;
  private final File file;
  private final long delayMillis;
  private final boolean end;
  private final TailerListener listener;
  private final boolean reOpen;
  private volatile boolean run = true;
  
  public Tailer(File file, TailerListener listener)
  {
    this(file, listener, 1000L);
  }
  
  public Tailer(File file, TailerListener listener, long delayMillis)
  {
    this(file, listener, delayMillis, false);
  }
  
  public Tailer(File file, TailerListener listener, long delayMillis, boolean end)
  {
    this(file, listener, delayMillis, end, 4096);
  }
  
  public Tailer(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen)
  {
    this(file, listener, delayMillis, end, reOpen, 4096);
  }
  
  public Tailer(File file, TailerListener listener, long delayMillis, boolean end, int bufSize)
  {
    this(file, listener, delayMillis, end, false, bufSize);
  }
  
  public Tailer(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufSize)
  {
    this.file = file;
    this.delayMillis = delayMillis;
    this.end = end;
    
    inbuf = new byte[bufSize];
    
    this.listener = listener;
    listener.init(this);
    this.reOpen = reOpen;
  }
  
  public static Tailer create(File file, TailerListener listener, long delayMillis, boolean end, int bufSize)
  {
    Tailer tailer = new Tailer(file, listener, delayMillis, end, bufSize);
    Thread thread = new Thread(tailer);
    thread.setDaemon(true);
    thread.start();
    return tailer;
  }
  
  public static Tailer create(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen, int bufSize)
  {
    Tailer tailer = new Tailer(file, listener, delayMillis, end, reOpen, bufSize);
    Thread thread = new Thread(tailer);
    thread.setDaemon(true);
    thread.start();
    return tailer;
  }
  
  public static Tailer create(File file, TailerListener listener, long delayMillis, boolean end)
  {
    return create(file, listener, delayMillis, end, 4096);
  }
  
  public static Tailer create(File file, TailerListener listener, long delayMillis, boolean end, boolean reOpen)
  {
    return create(file, listener, delayMillis, end, reOpen, 4096);
  }
  
  public static Tailer create(File file, TailerListener listener, long delayMillis)
  {
    return create(file, listener, delayMillis, false);
  }
  
  public static Tailer create(File file, TailerListener listener)
  {
    return create(file, listener, 1000L, false);
  }
  
  public File getFile()
  {
    return file;
  }
  
  public long getDelay()
  {
    return delayMillis;
  }
  
  public void run()
  {
    RandomAccessFile reader = null;
    try
    {
      long last = 0L;
      long position = 0L;
      while ((run) && (reader == null))
      {
        try
        {
          reader = new RandomAccessFile(file, "r");
        }
        catch (FileNotFoundException e)
        {
          listener.fileNotFound();
        }
        if (reader == null)
        {
          try
          {
            Thread.sleep(delayMillis);
          }
          catch (InterruptedException e) {}
        }
        else
        {
          position = end ? file.length() : 0L;
          last = System.currentTimeMillis();
          reader.seek(position);
        }
      }
      while (run)
      {
        boolean newer = FileUtils.isFileNewer(file, last);
        
        long length = file.length();
        if (length < position)
        {
          listener.fileRotated();
          try
          {
            save = reader;
            reader = new RandomAccessFile(file, "r");
            position = 0L;
          }
          catch (FileNotFoundException e)
          {
            RandomAccessFile save;
            listener.fileNotFound();
          }
        }
        else
        {
          if (length > position)
          {
            position = readLines(reader);
            last = System.currentTimeMillis();
          }
          else if (newer)
          {
            position = 0L;
            reader.seek(position);
            
            position = readLines(reader);
            last = System.currentTimeMillis();
          }
          if (reOpen) {
            IOUtils.closeQuietly(reader);
          }
          try
          {
            Thread.sleep(delayMillis);
          }
          catch (InterruptedException e) {}
          if ((run) && (reOpen))
          {
            reader = new RandomAccessFile(file, "r");
            reader.seek(position);
          }
        }
      }
    }
    catch (Exception e)
    {
      listener.handle(e);
    }
    finally
    {
      IOUtils.closeQuietly(reader);
    }
  }
  
  public void stop()
  {
    run = false;
  }
  
  private long readLines(RandomAccessFile reader)
    throws IOException
  {
    StringBuilder sb = new StringBuilder();
    
    long pos = reader.getFilePointer();
    long rePos = pos;
    
    boolean seenCR = false;
    int num;
    while ((run) && ((num = reader.read(inbuf)) != -1))
    {
      for (int i = 0; i < num; i++)
      {
        byte ch = inbuf[i];
        switch (ch)
        {
        case 10: 
          seenCR = false;
          listener.handle(sb.toString());
          sb.setLength(0);
          rePos = pos + i + 1L;
          break;
        case 13: 
          if (seenCR) {
            sb.append('\r');
          }
          seenCR = true;
          break;
        default: 
          if (seenCR)
          {
            seenCR = false;
            listener.handle(sb.toString());
            sb.setLength(0);
            rePos = pos + i + 1L;
          }
          sb.append((char)ch);
        }
      }
      pos = reader.getFilePointer();
    }
    reader.seek(rePos);
    return rePos;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.Tailer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

public abstract interface TailerListener
{
  public abstract void init(Tailer paramTailer);
  
  public abstract void fileNotFound();
  
  public abstract void fileRotated();
  
  public abstract void handle(String paramString);
  
  public abstract void handle(Exception paramException);
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.TailerListener
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

public class TailerListenerAdapter
  implements TailerListener
{
  public void init(Tailer tailer) {}
  
  public void fileNotFound() {}
  
  public void fileRotated() {}
  
  public void handle(String line) {}
  
  public void handle(Exception ex) {}
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.TailerListenerAdapter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class TeeInputStream
  extends ProxyInputStream
{
  private final OutputStream branch;
  private final boolean closeBranch;
  
  public TeeInputStream(InputStream input, OutputStream branch)
  {
    this(input, branch, false);
  }
  
  public TeeInputStream(InputStream input, OutputStream branch, boolean closeBranch)
  {
    super(input);
    this.branch = branch;
    this.closeBranch = closeBranch;
  }
  
  public void close()
    throws IOException
  {
    try
    {
      super.close();
    }
    finally
    {
      if (closeBranch) {
        branch.close();
      }
    }
  }
  
  public int read()
    throws IOException
  {
    int ch = super.read();
    if (ch != -1) {
      branch.write(ch);
    }
    return ch;
  }
  
  public int read(byte[] bts, int st, int end)
    throws IOException
  {
    int n = super.read(bts, st, end);
    if (n != -1) {
      branch.write(bts, st, n);
    }
    return n;
  }
  
  public int read(byte[] bts)
    throws IOException
  {
    int n = super.read(bts);
    if (n != -1) {
      branch.write(bts, 0, n);
    }
    return n;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.io.input.TeeInputStream
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.io.input;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.ByteOrderMark;

public class XmlStreamReader
  extends Reader
{
  private static final int BUFFER_SIZE = 4096;
  private static final String UTF_8 = "UTF-8";
  private static final String US_ASCII = "US-ASCII";
  private static final String UTF_16BE = "UTF-16BE";
  private static final String UTF_16LE = "UTF-16LE";
  private static final String UTF_32BE = "UTF-32BE";
  private static final String UTF_32LE = "UTF-32LE";
  private static final String UTF_16 = "UTF-16";
  private static final String UTF_32 = "UTF-32";
  private static final String EBCDIC = "CP1047";
  private static final ByteOrderMark[] BOMS = { ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE };
  private static final ByteOrderMark[] XML_GUESS_BYTES = { new ByteOrderMark("UTF-8", new int[] { 60, 63, 120, 109 }), new ByteOrderMark("UTF-16BE", new int[] { 0, 60, 0, 63 }), new ByteOrderMark("UTF-16LE", new int[] { 60, 0, 63, 0 }), new ByteOrderMark("UTF-32BE", new int[] { 0, 0, 0, 60, 0, 0, 0, 63, 0, 0, 0, 120, 0, 0, 0, 109 }), new ByteOrderMark("UTF-32LE", new int[] { 60, 0, 0, 0, 63, 0, 0, 0, 120, 0, 0, 0, 109, 0, 0, 0 }), new ByteOrderMark("CP1047", new int[] { 76, 111, 167, 148 }) };
  private final Reader reader;
  private final String encoding;
  private final String defaultEncoding;
  
  public String getDefaultEncoding()
  {
    return defaultEncoding;
  }
  
  public XmlStreamReader(File file)
    throws IOException
  {
    this(new FileInputStream(file));
  }
  
  public XmlStreamReader(InputStream is)
    throws IOException
  {
    this(is, true);
  }
  
  public XmlStreamReader(InputStream is, boolean lenient)
    throws IOException
  {
    this(is, lenient, null);
  }
  
  public XmlStreamReader(InputStream is, boolean lenient, String defaultEncoding)
    throws IOException
  {
    this.defaultEncoding = defaultEncoding;
    BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, 4096), false, BOMS);
    BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
    encoding = doRawStream(bom, pis, lenient);
    reader = new InputStreamReader(pis, encoding);
  }
  
  public XmlStreamReader(URL url)
    throws IOException
  {
    this(url.openConnection(), null);
  }
  
  public XmlStreamReader(URLConnection conn, String defaultEncoding)
    throws IOException
  {
    this.defaultEncoding = defaultEncoding;
    boolean lenient = true;
    String contentType = conn.getContentType();
    InputStream is = conn.getInputStream();
    BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, 4096), false, BOMS);
    BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
    if (((conn instanceof HttpURLConnection)) || (contentType != null)) {
      encoding = doHttpStream(bom, pis, contentType, lenient);
    } else {
      encoding = doRawStream(bom, pis, lenient);
    }
    reader = new InputStreamReader(pis, encoding);
  }
  
  public XmlStreamReader(InputStream is, String httpContentType)
    throws IOException
  {
    this(is, httpContentType, true);
  }
  
  public XmlStreamReader(InputStream is, String httpContentType, boolean lenient, String defaultEncoding)
    throws IOException
  {
    this.defaultEncoding = defaultEncoding;
    BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, 4096), false, BOMS);
    BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
    encoding = doHttpStream(bom, pis, httpContentType, lenient);
    reader = new InputStreamReader(pis, encoding);
  }
  
  public XmlStreamReader(InputStream is, String httpContentType, boolean lenient)
    throws IOException
  {
    this(is, httpContentType, lenient, null);
  }
  
  public String getEncoding()
  {
    return encoding;
  }
  
  public int read(char[] buf, int offset, int len)
    throws IOException
  {
    return reader.read(buf, offset, len);
  }
  
  public void close()
    throws IOException
  {
    reader.close();
  }
  
  private String doRawStream(BOMInputStream bom, BOMInputStream pis, boolean lenient)
    throws IOException
  {
    String bomEnc = bom.getBOMCharsetName();
    String xmlGuessEnc = pis.getBOMCharsetName();
    String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
    try
    {
      return calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
    }
    catch (XmlStreamReaderException ex)
    {
      if (lenient) {
        return doLenientDetection(null, ex);
      }
      throw ex;
    }
  }
  
  private String doHttpStream(BOMInputStream bom, BOMInputStream pis, String httpContentType, boolean lenient)
    throws IOException
  {
    String bomEnc = bom.getBOMCharsetName();
    String xmlGuessEnc = pis.getBOMCharsetName();
    String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
    try
    {
      return calculateHttpEncoding(httpContentType, bomEnc, xmlGuessEnc, xmlEnc, lenient);
    }
    catch (XmlStreamReaderException ex)
    {
      if (lenient) {
        return doLenientDetection(httpContentType, ex);
      }
      throw ex;
    }
  }
  
  private String doLenientDetection(String httpContentType, XmlStreamReaderException ex)
    throws IOException
  {
    if ((httpContentType != null) && (httpContentType.startsWith("text/html")))
    {
      httpContentType = httpContentType.substring("text/html".length());
      httpContentType = "text/xml" + httpContentType;
      try
      {
        return calculateHttpEncoding(httpContentType, ex.getBomEncoding(), ex.getXmlGuessEncoding(), ex.getXmlEncoding(), true);
      }
      catch (XmlStreamReaderException ex2)
      {
        ex = ex2;
      }
    }
    String encoding = ex.getXmlEncoding();
    if (encoding == null) {
      encoding = ex.getContentTypeEncoding();
    }
    if (encoding == null) {
      encoding = defaultEncoding == null ? "UTF-8" : defaultEncoding;
    }
    return encoding;
  }
  
  String calculateRawEncoding(String bomEnc, String xmlGuessEnc, String xmlEnc)
    throws IOException
  {
    if (bomEnc == null)
    {
      if ((xmlGuessEnc == null) || (xmlEnc == null)) {
        return defaultEncoding == null ? "UTF-8" : defaultEncoding;
      }
      if ((xmlEnc.equals("UTF-16")) && ((xmlGuessEnc.equals("UTF-16BE")) || (xmlGuessEnc.equals("UTF-16LE")))) {
        return xmlGuessEnc;
      }
      return xmlEnc;
    }
    if (bomEnc.equals("UTF-8"))
    {
      if ((xmlGuessEnc != null) && (!xmlGuessEnc.equals("UTF-8")))
      {
        String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
      }
      if ((xmlEnc != null) && (!xmlEnc.equals("UTF-8")))
      {
        String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
      }
      return bomEnc;
    }
    if ((bomEnc.equals("UTF-16BE")) || (bomEnc.equals("UTF-16LE")))
    {
      if ((xmlGuessEnc != null) && (!xmlGuessEnc.equals(bomEnc)))
      {
        String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
      }
      if ((xmlEnc != null) && (!xmlEnc.equals("UTF-16")) && (!xmlEnc.equals(bomEnc)))
      {
        String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
      }
      return bomEnc;
    }
    if ((bomEnc.equals("UTF-32BE")) || (bomEnc.equals("UTF-32LE")))
    {
      if ((xmlGuessEnc != null) && (!xmlGuessEnc.equals(bomEnc)))
      {
        String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
      }
      if ((xmlEnc != null) && (!xmlEnc.equals("UTF-32")) && (!xmlEnc.equals(bomEnc)))
      {
        String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
      }
      return bomEnc;
    }
    String msg = MessageFormat.format("Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM", new Object[] { bomEnc, xmlGuessEnc, xmlEnc });
    throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
  }
  
  String calculateHttpEncoding(String httpContentType, String bomEnc, String xmlGuessEnc, String xmlEnc, boolean lenient)
    throws IOException
  {
    if ((lenient) && (xmlEnc != null)) {
      return xmlEnc;
    }
    String cTMime = getContentTypeMime(httpContentType);
    String cTEnc = getContentTypeEncoding(httpContentType);
    boolean appXml = isAppXml(cTMime);
    boolean textXml = isTextXml(cTMime);
    if ((!appXml) && (!textXml))
    {
      String msg = MessageFormat.format("Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME", new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc });
      throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
    }
    if (cTEnc == null)
    {
      if (appXml) {
        return calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
      }
      return defaultEncoding == null ? "US-ASCII" : defaultEncoding;
    }
    if ((cTEnc.equals("UTF-16BE")) || (cTEnc.equals("UTF-16LE")))
    {
      if (bomEnc != null)
      {
        String msg = MessageFormat.format("Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL", new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
      }
      return cTEnc;
    }
    if (cTEnc.equals("UTF-16"))
    {
      if ((bomEnc != null) && (bomEnc.startsWith("UTF-16"))) {
        return bomEnc;
      }
      String msg = MessageFormat.format("Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch", new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc });
      throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
    }
    if ((cTEnc.equals("UTF-32BE")) || (cTEnc.equals("UTF-32LE")))
    {
      if (bomEnc != null)
      {
        String msg = MessageFormat.format("Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL", new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc });
        throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
      }
      return cTEnc;
    }
    if (cTEnc.equals("UTF-32"))
    {
      if ((bomEnc != null) && (bomEnc.startsWith("UTF-32"))) {
        return bomEnc;
      }
      String msg = MessageFormat.format("Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch", new Object[] { cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc });
      throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
    }
    return cTEnc;
  }
  
  static String getContentTypeMime(String httpContentType)
  {
    String mime = null;
    if (httpContentType != null)
    {
      int i = httpContentType.indexOf(";");
      if (i >= 0) {
        mime = httpContentType.substring(0, i);
      } else {
        mime = httpContentType;
      }
      mime = mime.trim();
    }
    return mime;
  }
  
  private static final Pattern CHARSET_PATTERN = Pattern.compile("charset=[\"']?([.[^; \"']]*)[\"']?");
  
  static String getContentTypeEncoding(String httpContentType)
  {
    String encoding = null;
    if (httpContentType != null)
    {
      int i = httpContentType.indexOf(";");
      if (i > -1)
      {
        String postMime = httpContentType.substring(i + 1);
        Matcher m = CHARSET_PATTERN.matcher(postMime);
        encoding = m.find() ? m.group(1) : null;
        encoding = encoding != null ? encoding.toUpperCase(Locale.US) : null;
      }
    }
    return encoding;
  }
  
  public static final Pattern ENCODING_PATTERN = Pattern.compile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd