gt:       else if (utflen == 0xFFFF)
context: /*
   * Copyright 2015 The SageTV Authors. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *  http:
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package jcog.io;
  
  /* buffers writes to a RandomAccessFile */
  /* flush() must be called after you're done writing a chunk.
   * TODO needs Test */
  public class FastRandomFile implements java.io.DataOutput, java.io.DataInput
  {
    protected java.io.RandomAccessFile raf = null;
      protected byte[] buff = new byte[65536];
    protected int buffptr = 0;
    protected long fp = 0;
  
    public FastRandomFile(String name, String mode, String inCharset) throws java.io.IOException
    {
      myCharset = inCharset;
  
  
  
      raf = new java.io.RandomAccessFile(name, mode);
  
  
    }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
    
    protected FastRandomFile(String inCharset) {
      myCharset = inCharset;
      
    }
  
    public long getFilePointer()
    {
      return fp;
    }
  
    public void close() throws java.io.IOException
    {
      flush();
      
      try
      {
        raf.getFD().sync();
      }
      catch (Throwable t)
      {
        
      }
  
      raf.close();
      buff = null;
    }
  
    public void fullFlush() throws java.io.IOException
    {
      flush();
      raf.getFD().sync();
    }
  
    public void write(int b) throws java.io.IOException
    {
      write((byte)(b & 0xFF));
    }
  
    public void write(byte b) throws java.io.IOException
    {
  
  
  
  
      if (circularFileSize > 0 && fp == circularFileSize)
        seek(0);
      fp++;
      buff[buffptr++] = b;
      if (buffptr == buff.length)
        flush();
    }
  
    public void writeUnencryptedByte(byte b) throws java.io.IOException
    {
      fp++;
      buff[buffptr++] = b;
      if (buffptr == buff.length)
        flush();
    }
  
    public void flush() throws java.io.IOException
    {
      if (buffptr > 0)
      {
        raf.write(buff, 0, buffptr);
        buffptr = 0;
      }
    }
  
    
    
    
    
    private final byte[] intWriteBuf = new byte[4];
    public void writeIntAtOffset(long targetFp, int s) throws java.io.IOException
    {
      byte b1 = (byte)((s >>> 24) & 0xFF);
      byte b2 = (byte)((s >>> 16) & 0xFF);
      byte b3 = (byte)((s >>> 8) & 0xFF);
      byte b4 = (byte)(s & 0xFF);
  
  
  
  
  
  
  
      
      
      int skipBackWriteAmount = Math.min(4, (int)(fp - buffptr - targetFp));
      if (skipBackWriteAmount > 0)
      {
        intWriteBuf[0] = b1; intWriteBuf[1] = b2; intWriteBuf[2] = b3; intWriteBuf[3] = b4;
        raf.seek(targetFp);
        raf.write(intWriteBuf, 0, skipBackWriteAmount);
        raf.seek(fp - buffptr);
      }
  
      if (skipBackWriteAmount < 1)
        buff[buffptr - ((int)(fp - targetFp))] = b1;
      if (skipBackWriteAmount < 2)
        buff[buffptr - ((int)(fp - targetFp)) + 1] = b2;
      if (skipBackWriteAmount < 3)
        buff[buffptr - ((int)(fp - targetFp)) + 2] = b3;
      if (skipBackWriteAmount < 4)
        buff[buffptr - ((int)(fp - targetFp)) + 3] = b4;
    }
  
    public void write(byte[] b, int off, int len) throws java.io.IOException
    {
      if (/*crypto || */circularFileSize > 0)
      {
        while (len-- > 0)
          write(b[off++]);
      }
      else
      {
        while (len > 0)
        {
          int rem = buff.length - buffptr;
          if (len < rem)
          {
            System.arraycopy(b, off, buff, buffptr, len);
            buffptr += len;
            fp += len;
            break;
          }
          else
          {
            System.arraycopy(b, off, buff, buffptr, rem);
            buffptr += rem;
            off += rem;
            len -= rem;
            fp += rem;
            flush();
          }
        }
      }
    }
  
    public void write(byte[] b)	throws java.io.IOException
    {
      write(b, 0, b.length);
    }
  
    public void seek(long newfp) throws java.io.IOException
    {
      flush();
      raf.seek(fp = newfp);
    }
  
    public int read() throws java.io.IOException
    {
  
  
  
  
  
  
  
  
      {
        fp++;
        return raf.read();
      }
    }
  
    public boolean readBoolean() throws java.io.IOException
    {
      int ch = read();
      if (ch < 0)
        throw new java.io.EOFException();
      return (ch != 0);
    }
  
    public byte readByte() throws java.io.IOException
    {
      int ch = read();
      if (ch < 0)
        throw new java.io.EOFException();
      return (byte)(ch);
    }
  
    public byte readUnencryptedByte() throws java.io.IOException
    {
      fp++;
      int ch = raf.read();
      if (ch < 0)
        throw new java.io.EOFException();
      return (byte)(ch);
    }
  
    public int readInt() throws java.io.IOException
    {
      int b1 = this.read();
      int b2 = this.read();
      int b3 = this.read();
      int b4 = this.read();
      if ((b1 | b2 | b3 | b4) < 0)
        throw new java.io.EOFException();
      return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4;
    }
  
    public long readLong() throws java.io.IOException
    {
      return ((long)(readInt()) << 32) + (readInt() & 0xFFFFFFFFL);
    }
  
    
    private byte[] bytearr = null;
    private char[] chararr = null;
    
    
    public String readUTF()	throws java.io.IOException
    {
      if (isI18N)
      {
        int utflen = readUnsignedShort();
        if (utflen == 0)
          return "";
  