home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class RandomAccessFile implements DataOutput, DataInput {
- // $FF: renamed from: fd java.io.FileDescriptor
- private FileDescriptor field_0;
-
- public RandomAccessFile(String name, String mode) throws IOException {
- boolean rw = mode.equals("rw");
- if (!rw && !mode.equals("r")) {
- throw new IllegalArgumentException("mode must be r or rw");
- } else {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(name);
- if (rw) {
- security.checkWrite(name);
- }
- }
-
- this.field_0 = new FileDescriptor();
- this.open(name, rw);
- }
- }
-
- public RandomAccessFile(File file, String mode) throws IOException {
- this(file.getPath(), mode);
- }
-
- public final FileDescriptor getFD() throws IOException {
- if (this.field_0 != null) {
- return this.field_0;
- } else {
- throw new IOException();
- }
- }
-
- private native void open(String var1, boolean var2) throws IOException;
-
- public native int read() throws IOException;
-
- private native int readBytes(byte[] var1, int var2, int var3) throws IOException;
-
- public int read(byte[] b, int off, int len) throws IOException {
- return this.readBytes(b, off, len);
- }
-
- public int read(byte[] b) throws IOException {
- return this.readBytes(b, 0, b.length);
- }
-
- public final void readFully(byte[] b) throws IOException {
- this.readFully(b, 0, b.length);
- }
-
- public final void readFully(byte[] b, int off, int len) throws IOException {
- int count;
- for(int n = 0; n < len; n += count) {
- count = this.read(b, off + n, len - n);
- if (count < 0) {
- throw new EOFException();
- }
- }
-
- }
-
- public int skipBytes(int n) throws IOException {
- this.seek(this.getFilePointer() + (long)n);
- return n;
- }
-
- public native void write(int var1) throws IOException;
-
- private native void writeBytes(byte[] var1, int var2, int var3) throws IOException;
-
- public void write(byte[] b) throws IOException {
- this.writeBytes(b, 0, b.length);
- }
-
- public void write(byte[] b, int off, int len) throws IOException {
- this.writeBytes(b, off, len);
- }
-
- public native long getFilePointer() throws IOException;
-
- public native void seek(long var1) throws IOException;
-
- public native long length() throws IOException;
-
- public native void close() throws IOException;
-
- public final boolean readBoolean() throws IOException {
- int ch = this.read();
- if (ch < 0) {
- throw new EOFException();
- } else {
- return ch != 0;
- }
- }
-
- public final byte readByte() throws IOException {
- int ch = this.read();
- if (ch < 0) {
- throw new EOFException();
- } else {
- return (byte)ch;
- }
- }
-
- public final int readUnsignedByte() throws IOException {
- int ch = this.read();
- if (ch < 0) {
- throw new EOFException();
- } else {
- return ch;
- }
- }
-
- public final short readShort() throws IOException {
- int ch1 = this.read();
- int ch2 = this.read();
- if ((ch1 | ch2) < 0) {
- throw new EOFException();
- } else {
- return (short)((ch1 << 8) + ch2);
- }
- }
-
- public final int readUnsignedShort() throws IOException {
- int ch1 = this.read();
- int ch2 = this.read();
- if ((ch1 | ch2) < 0) {
- throw new EOFException();
- } else {
- return (ch1 << 8) + ch2;
- }
- }
-
- public final char readChar() throws IOException {
- int ch1 = this.read();
- int ch2 = this.read();
- if ((ch1 | ch2) < 0) {
- throw new EOFException();
- } else {
- return (char)((ch1 << 8) + ch2);
- }
- }
-
- public final int readInt() throws IOException {
- int ch1 = this.read();
- int ch2 = this.read();
- int ch3 = this.read();
- int ch4 = this.read();
- if ((ch1 | ch2 | ch3 | ch4) < 0) {
- throw new EOFException();
- } else {
- return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + ch4;
- }
- }
-
- public final long readLong() throws IOException {
- return ((long)this.readInt() << 32) + ((long)this.readInt() & 4294967295L);
- }
-
- public final float readFloat() throws IOException {
- return Float.intBitsToFloat(this.readInt());
- }
-
- public final double readDouble() throws IOException {
- return Double.longBitsToDouble(this.readLong());
- }
-
- public final String readLine() throws IOException {
- StringBuffer input = new StringBuffer();
-
- int c;
- while((c = this.read()) != -1 && c != 10) {
- input.append((char)c);
- }
-
- return c == -1 && input.length() == 0 ? null : input.toString();
- }
-
- public final String readUTF() throws IOException {
- return DataInputStream.readUTF(this);
- }
-
- public final void writeBoolean(boolean v) throws IOException {
- this.write(v ? 1 : 0);
- }
-
- public final void writeByte(int v) throws IOException {
- this.write(v);
- }
-
- public final void writeShort(int v) throws IOException {
- this.write(v >>> 8 & 255);
- this.write(v & 255);
- }
-
- public final void writeChar(int v) throws IOException {
- this.write(v >>> 8 & 255);
- this.write(v & 255);
- }
-
- public final void writeInt(int v) throws IOException {
- this.write(v >>> 24 & 255);
- this.write(v >>> 16 & 255);
- this.write(v >>> 8 & 255);
- this.write(v & 255);
- }
-
- public final void writeLong(long v) throws IOException {
- this.write((int)(v >>> 56) & 255);
- this.write((int)(v >>> 48) & 255);
- this.write((int)(v >>> 40) & 255);
- this.write((int)(v >>> 32) & 255);
- this.write((int)(v >>> 24) & 255);
- this.write((int)(v >>> 16) & 255);
- this.write((int)(v >>> 8) & 255);
- this.write((int)v & 255);
- }
-
- public final void writeFloat(float v) throws IOException {
- this.writeInt(Float.floatToIntBits(v));
- }
-
- public final void writeDouble(double v) throws IOException {
- this.writeLong(Double.doubleToLongBits(v));
- }
-
- public final void writeBytes(String s) throws IOException {
- int len = s.length();
-
- for(int i = 0; i < len; ++i) {
- this.write((byte)s.charAt(i));
- }
-
- }
-
- public final void writeChars(String s) throws IOException {
- int len = s.length();
-
- for(int i = 0; i < len; ++i) {
- int v = s.charAt(i);
- this.write(v >>> 8 & 255);
- this.write(v & 255);
- }
-
- }
-
- public final void writeUTF(String str) throws IOException {
- int strlen = str.length();
- int utflen = 0;
-
- for(int i = 0; i < strlen; ++i) {
- int c = str.charAt(i);
- if (c >= 1 && c <= 127) {
- ++utflen;
- } else if (c > 2047) {
- utflen += 3;
- } else {
- utflen += 2;
- }
- }
-
- this.write(utflen >>> 8 & 255);
- this.write(utflen & 255);
-
- for(int i = 0; i < strlen; ++i) {
- int c = str.charAt(i);
- if (c >= 1 && c <= 127) {
- this.write(c);
- } else if (c > 2047) {
- this.write(224 | c >> 12 & 15);
- this.write(128 | c >> 6 & 63);
- this.write(128 | c & 63);
- } else {
- this.write(192 | c >> 6 & 31);
- this.write(128 | c & 63);
- }
- }
-
- }
- }
-