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