home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / RandomAccessFile.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  5.3 KB  |  292 lines

  1. package java.io;
  2.  
  3. public class RandomAccessFile implements DataOutput, DataInput {
  4.    // $FF: renamed from: fd java.io.FileDescriptor
  5.    private FileDescriptor field_0;
  6.  
  7.    public RandomAccessFile(String var1, String var2) throws IOException {
  8.       boolean var3 = var2.equals("rw");
  9.       if (!var3 && !var2.equals("r")) {
  10.          throw new IllegalArgumentException("mode must be r or rw");
  11.       } else {
  12.          SecurityManager var4 = System.getSecurityManager();
  13.          if (var4 != null) {
  14.             var4.checkRead(var1);
  15.             if (var3) {
  16.                var4.checkWrite(var1);
  17.             }
  18.          }
  19.  
  20.          this.field_0 = new FileDescriptor();
  21.          this.open(var1, var3);
  22.       }
  23.    }
  24.  
  25.    public RandomAccessFile(File var1, String var2) throws IOException {
  26.       this(var1.getPath(), var2);
  27.    }
  28.  
  29.    public final FileDescriptor getFD() throws IOException {
  30.       if (this.field_0 != null) {
  31.          return this.field_0;
  32.       } else {
  33.          throw new IOException();
  34.       }
  35.    }
  36.  
  37.    private native void open(String var1, boolean var2) throws IOException;
  38.  
  39.    public native int read() throws IOException;
  40.  
  41.    private native int readBytes(byte[] var1, int var2, int var3) throws IOException;
  42.  
  43.    public int read(byte[] var1, int var2, int var3) throws IOException {
  44.       return this.readBytes(var1, var2, var3);
  45.    }
  46.  
  47.    public int read(byte[] var1) throws IOException {
  48.       return this.readBytes(var1, 0, var1.length);
  49.    }
  50.  
  51.    public final void readFully(byte[] var1) throws IOException {
  52.       this.readFully(var1, 0, var1.length);
  53.    }
  54.  
  55.    public final void readFully(byte[] var1, int var2, int var3) throws IOException {
  56.       int var5;
  57.       for(int var4 = 0; var4 < var3; var4 += var5) {
  58.          var5 = this.read(var1, var2 + var4, var3 - var4);
  59.          if (var5 < 0) {
  60.             throw new EOFException();
  61.          }
  62.       }
  63.  
  64.    }
  65.  
  66.    public int skipBytes(int var1) throws IOException {
  67.       this.seek(this.getFilePointer() + (long)var1);
  68.       return var1;
  69.    }
  70.  
  71.    public native void write(int var1) throws IOException;
  72.  
  73.    private native void writeBytes(byte[] var1, int var2, int var3) throws IOException;
  74.  
  75.    public void write(byte[] var1) throws IOException {
  76.       this.writeBytes(var1, 0, var1.length);
  77.    }
  78.  
  79.    public void write(byte[] var1, int var2, int var3) throws IOException {
  80.       this.writeBytes(var1, var2, var3);
  81.    }
  82.  
  83.    public native long getFilePointer() throws IOException;
  84.  
  85.    public native void seek(long var1) throws IOException;
  86.  
  87.    public native long length() throws IOException;
  88.  
  89.    public native void close() throws IOException;
  90.  
  91.    public final boolean readBoolean() throws IOException {
  92.       int var1 = this.read();
  93.       if (var1 < 0) {
  94.          throw new EOFException();
  95.       } else {
  96.          return var1 != 0;
  97.       }
  98.    }
  99.  
  100.    public final byte readByte() throws IOException {
  101.       int var1 = this.read();
  102.       if (var1 < 0) {
  103.          throw new EOFException();
  104.       } else {
  105.          return (byte)var1;
  106.       }
  107.    }
  108.  
  109.    public final int readUnsignedByte() throws IOException {
  110.       int var1 = this.read();
  111.       if (var1 < 0) {
  112.          throw new EOFException();
  113.       } else {
  114.          return var1;
  115.       }
  116.    }
  117.  
  118.    public final short readShort() throws IOException {
  119.       int var1 = this.read();
  120.       int var2 = this.read();
  121.       if ((var1 | var2) < 0) {
  122.          throw new EOFException();
  123.       } else {
  124.          return (short)((var1 << 8) + var2);
  125.       }
  126.    }
  127.  
  128.    public final int readUnsignedShort() throws IOException {
  129.       int var1 = this.read();
  130.       int var2 = this.read();
  131.       if ((var1 | var2) < 0) {
  132.          throw new EOFException();
  133.       } else {
  134.          return (var1 << 8) + var2;
  135.       }
  136.    }
  137.  
  138.    public final char readChar() throws IOException {
  139.       int var1 = this.read();
  140.       int var2 = this.read();
  141.       if ((var1 | var2) < 0) {
  142.          throw new EOFException();
  143.       } else {
  144.          return (char)((var1 << 8) + var2);
  145.       }
  146.    }
  147.  
  148.    public final int readInt() throws IOException {
  149.       int var1 = this.read();
  150.       int var2 = this.read();
  151.       int var3 = this.read();
  152.       int var4 = this.read();
  153.       if ((var1 | var2 | var3 | var4) < 0) {
  154.          throw new EOFException();
  155.       } else {
  156.          return (var1 << 24) + (var2 << 16) + (var3 << 8) + var4;
  157.       }
  158.    }
  159.  
  160.    public final long readLong() throws IOException {
  161.       return ((long)this.readInt() << 32) + ((long)this.readInt() & 4294967295L);
  162.    }
  163.  
  164.    public final float readFloat() throws IOException {
  165.       return Float.intBitsToFloat(this.readInt());
  166.    }
  167.  
  168.    public final double readDouble() throws IOException {
  169.       return Double.longBitsToDouble(this.readLong());
  170.    }
  171.  
  172.    public final String readLine() throws IOException {
  173.       StringBuffer var1 = new StringBuffer();
  174.  
  175.       int var2;
  176.       while((var2 = this.read()) != -1 && var2 != 10) {
  177.          var1.append((char)var2);
  178.       }
  179.  
  180.       return var2 == -1 && var1.length() == 0 ? null : var1.toString();
  181.    }
  182.  
  183.    public final String readUTF() throws IOException {
  184.       return DataInputStream.readUTF(this);
  185.    }
  186.  
  187.    public final void writeBoolean(boolean var1) throws IOException {
  188.       this.write(var1 ? 1 : 0);
  189.    }
  190.  
  191.    public final void writeByte(int var1) throws IOException {
  192.       this.write(var1);
  193.    }
  194.  
  195.    public final void writeShort(int var1) throws IOException {
  196.       this.write(var1 >>> 8 & 255);
  197.       this.write(var1 & 255);
  198.    }
  199.  
  200.    public final void writeChar(int var1) throws IOException {
  201.       this.write(var1 >>> 8 & 255);
  202.       this.write(var1 & 255);
  203.    }
  204.  
  205.    public final void writeInt(int var1) throws IOException {
  206.       this.write(var1 >>> 24 & 255);
  207.       this.write(var1 >>> 16 & 255);
  208.       this.write(var1 >>> 8 & 255);
  209.       this.write(var1 & 255);
  210.    }
  211.  
  212.    public final void writeLong(long var1) throws IOException {
  213.       this.write((int)(var1 >>> 56) & 255);
  214.       this.write((int)(var1 >>> 48) & 255);
  215.       this.write((int)(var1 >>> 40) & 255);
  216.       this.write((int)(var1 >>> 32) & 255);
  217.       this.write((int)(var1 >>> 24) & 255);
  218.       this.write((int)(var1 >>> 16) & 255);
  219.       this.write((int)(var1 >>> 8) & 255);
  220.       this.write((int)var1 & 255);
  221.    }
  222.  
  223.    public final void writeFloat(float var1) throws IOException {
  224.       this.writeInt(Float.floatToIntBits(var1));
  225.    }
  226.  
  227.    public final void writeDouble(double var1) throws IOException {
  228.       this.writeLong(Double.doubleToLongBits(var1));
  229.    }
  230.  
  231.    public final void writeBytes(String var1) throws IOException {
  232.       int var2 = var1.length();
  233.       byte[] var3 = new byte[var2];
  234.       var1.getBytes(0, var2, var3, 0);
  235.       this.writeBytes(var3, 0, var2);
  236.    }
  237.  
  238.    public final void writeChars(String var1) throws IOException {
  239.       int var2 = var1.length();
  240.       int var3 = 2 * var2;
  241.       byte[] var4 = new byte[var3];
  242.       char[] var5 = new char[var2];
  243.       var1.getChars(0, var2, var5, 0);
  244.       int var6 = 0;
  245.  
  246.       for(int var7 = 0; var6 < var2; ++var6) {
  247.          var4[var7++] = (byte)(var5[var6] >>> 8);
  248.          var4[var7++] = (byte)var5[var6];
  249.       }
  250.  
  251.       this.writeBytes(var4, 0, var3);
  252.    }
  253.  
  254.    public final void writeUTF(String var1) throws IOException {
  255.       int var2 = var1.length();
  256.       int var3 = 0;
  257.  
  258.       for(int var4 = 0; var4 < var2; ++var4) {
  259.          char var5 = var1.charAt(var4);
  260.          if (var5 >= 1 && var5 <= 127) {
  261.             ++var3;
  262.          } else if (var5 > 2047) {
  263.             var3 += 3;
  264.          } else {
  265.             var3 += 2;
  266.          }
  267.       }
  268.  
  269.       if (var3 > 65535) {
  270.          throw new UTFDataFormatException();
  271.       } else {
  272.          this.write(var3 >>> 8 & 255);
  273.          this.write(var3 & 255);
  274.  
  275.          for(int var7 = 0; var7 < var2; ++var7) {
  276.             char var6 = var1.charAt(var7);
  277.             if (var6 >= 1 && var6 <= 127) {
  278.                this.write(var6);
  279.             } else if (var6 > 2047) {
  280.                this.write(224 | var6 >> 12 & 15);
  281.                this.write(128 | var6 >> 6 & 63);
  282.                this.write(128 | var6 & 63);
  283.             } else {
  284.                this.write(192 | var6 >> 6 & 31);
  285.                this.write(128 | var6 & 63);
  286.             }
  287.          }
  288.  
  289.       }
  290.    }
  291. }
  292.