import java.io.*;
import java.net.ProtocolException;

public class ExceptionlessRandomAccessFile extends RandomAccessFile
{
  public ExceptionlessRandomAccessFile( File file, String mode ) throws FileNotFoundException
  {
    super( file, mode );
  }

  @Override
  public long length()
  {
    try
    {
      return super.length();
    }
    catch ( IOException e )
    {
      return 0;
    }
  }

  @Override
  public void write( int b ) throws ProtocolException
  {
    try
    {
      super.write( b );
    }
    catch ( IOException e )
    {
      throw new ProtocolException();
    }
  }
  
  public static void main( String[] args )
  {
    RandomAccessFile raf = null;

    try
    {
      raf = new ExceptionlessRandomAccessFile( new File("file"), "r" );
    }
    catch ( FileNotFoundException e )
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

      try
      {
        raf.length();
      }
      catch ( IOException e ) { }
  }
}
