diff --git a/rtl/java/Files.java b/rtl/java/Files.java
index 5fe0074ca6293714b95895c070a78113ee14fcbe..17694523dbba69ef510b4d21ffb0b4965c3f72df 100644 (file)
--- a/rtl/java/Files.java
+++ b/rtl/java/Files.java
try
{
- filepath = File.createTempFile(RandomString(8), "tmp");
- fileregpath = new File(SYSTEM.STRING(name));
+ String s = (name[0] == 0) ? (".TMP") : SYSTEM.STRING(name);
+ filepath = File.createTempFile(s, "tmp");
+ fileregpath = new File(s);
filedesc = new RandomAccessFile(filepath, "rw");
}
catch(IOException e)
file = new RECORD0();
file.path = filepath;
- file.regpath = fileregpath;
+ file.regpath = fileregpath.getAbsoluteFile();
file.desc = filedesc;
return file;
}
public static void Register(RECORD0 f)
+ throws
+ IOException
{
- f.path.renameTo(f.regpath);
+ java.nio.file.Files.move(
+ java.nio.file.Paths.get(f.path.getPath()),
+ java.nio.file.Paths.get(f.regpath.getPath()),
+ java.nio.file.StandardCopyOption.REPLACE_EXISTING
+ );
f.path = f.regpath;
}
public static void ReadInt(RECORD1 R[], int R$, short x[], int x$)
{
- RECORD1 rider = R[R$];
- RandomAccessFile desc = rider.base.desc;
-
- try
- {
- rider.base.SetActive(rider);
- byte[] buf = new byte[2];
- rider.res[0] = desc.read(buf, 0, 2);
- rider.eof[0] = (rider.res[0] != 0);
- x[x$] = (short) (((buf[1] & 0xff) << 8) | (buf[0] & 0xff));
- rider.position += 2 - rider.res[0];
- }
- catch(IOException e)
- {
- rider.res[0] = 2;
- rider.eof[0] = true;
- }
+ byte[][] buf = new byte[1][2];
+ ReadBytes(R, R$, buf, 0, 2);
+ x[x$] = (short) ((buf[0][1] & 0xff) << 8);
+ x[x$] |= (short) (buf[0][0] & 0xff);
}
public static void ReadLInt(RECORD1 R[], int R$, int x[], int x$)
{
- RECORD1 rider = R[R$];
- RandomAccessFile desc = rider.base.desc;
+ byte[][] buf = new byte[1][4];
+ ReadBytes(R, R$, buf, 0, 4);
+ x[x$] = (int) ((buf[0][3] & 0xff) << 24);
+ x[x$] |= (int) ((buf[0][2] & 0xff) << 16);
+ x[x$] |= (int) ((buf[0][1] & 0xff) << 8);
+ x[x$] |= (int) ((buf[0][0] & 0xff));
+ }
- try
- {
- rider.base.SetActive(rider);
- byte[] buf = new byte[4];
- rider.res[0] = desc.read(buf, 0, 4);
- rider.eof[0] = (rider.res[0] != 0);
- x[x$] = ((buf[3] & 0xff) << 24) | ((buf[2] & 0xff) << 16) | ((buf[1] & 0xff) << 8) | (buf[0] & 0xff);
- rider.position += 4 - rider.res[0];
- }
- catch(IOException e)
- {
- rider.res[0] = 4;
- rider.eof[0] = true;
- }
+ public static void ReadHInt(RECORD1 R[], int R$, long x[], int x$)
+ {
+ byte[][] buf = new byte[1][8];
+ ReadBytes(R, R$, buf, 0, 8);
+ x[x$] = (buf[0][7] & 0xff) << 56;
+ x[x$] |= (buf[0][6] & 0xff) << 48;
+ x[x$] |= (buf[0][5] & 0xff) << 40;
+ x[x$] |= (buf[0][4] & 0xff) << 32;
+ x[x$] |= (buf[0][3] & 0xff) << 24;
+ x[x$] |= (buf[0][2] & 0xff) << 16;
+ x[x$] |= (buf[0][1] & 0xff) << 8;
+ x[x$] |= (buf[0][0] & 0xff);
}
public static void ReadReal(RECORD1 R[], int R$, float x[], int x$)
{
- RECORD1 rider = R[R$];
- RandomAccessFile desc = rider.base.desc;
-
- try
- {
- rider.base.SetActive(rider);
- x[x$] = desc.readFloat();
- rider.position += 4;
- }
- catch(IOException e)
- {
- rider.res[0] = 4;
- rider.eof[0] = true;
- }
+ int[] i = new int[1];
+ ReadLInt(R, R$, i, 0);
+ x[x$] = Float.intBitsToFloat(i[0]);
}
public static void ReadLReal(RECORD1 R[], int R$, double x[], int x$)
{
- RECORD1 rider = R[R$];
- RandomAccessFile desc = rider.base.desc;
-
- try
- {
- rider.base.SetActive(rider);
- x[x$] = desc.readDouble();
- rider.position += 8;
- }
- catch(IOException e)
- {
- rider.res[0] = 8;
- rider.eof[0] = true;
- }
+ long[] i = new long[1];
+ ReadHInt(R, R$, i, 0);
+ x[x$] = Double.longBitsToDouble(i[0]);
}
public static void ReadNum(RECORD1 R[], int R$, int x[], int x$)
public static void ReadBool(RECORD1 R[], int R$, boolean x[], int x$)
{
- RECORD1 rider = R[R$];
+ byte[] i = new byte[1];
+ Read(R, R$, i, 0);
+ x[x$] = (i[0] != 0);
+ }
+
+ public static void ReadBytes(RECORD1 r[], int r$, byte x[][], int x$, int n)
+ {
+ RECORD1 rider = r[r$];
RandomAccessFile desc = rider.base.desc;
try
{
rider.base.SetActive(rider);
- int i = desc.read();
- x[x$] = (i != 0);
- rider.position += 1;
+ int readed = desc.read(x[x$], 0, n);
+ rider.res[0] = (readed >= 0) ? (n - readed) : (0);
+ rider.eof[0] = (rider.res[0] != 0);
+ rider.position += (readed >= 0) ? (readed) : (0);
}
catch(IOException e)
{
- rider.res[0] = 1;
+ e.printStackTrace();
+ rider.res[0] = n;
rider.eof[0] = true;
- }
+ }
}
- public static void ReadBytes(RECORD1 r[], int r$, byte x[][], int x$, int n)
+ public static void Write(RECORD1 r[], int r$, byte x)
{
RECORD1 rider = r[r$];
RandomAccessFile desc = rider.base.desc;
try
{
rider.base.SetActive(rider);
- rider.res[0] = desc.read(x[x$], 0, n);
- rider.eof[0] = (rider.res[0] != 0);
- rider.position += n - rider.res[0];
+ desc.write(x);
+ rider.position += 1;
}
catch(IOException e)
{
- e.printStackTrace();
- rider.res[0] = n;
+ rider.res[0] = 1;
rider.eof[0] = true;
}
}
- public static void Write(RECORD1 r[], int r$, byte x)
- {
- SYSTEM.TRAP(-3);
- }
-
public static void WriteInt(RECORD1 R[], int R$, short x)
{
- SYSTEM.TRAP(-3);
+ byte[][] i = new byte[1][2];
+ i[0][1] = (byte) ((x >>> 8) & 0xff);
+ i[0][0] = (byte) ((x) & 0xff);
+ WriteBytes(R, R$, i, 0, 2);
}
public static void WriteLInt(RECORD1 R[], int R$, int x)
{
- SYSTEM.TRAP(-3);
+ byte[][] i = new byte[1][4];
+ i[0][3] = (byte) ((x >>> 24) & 0xff);
+ i[0][2] = (byte) ((x >>> 16) & 0xff);
+ i[0][1] = (byte) ((x >>> 8) & 0xff);
+ i[0][0] = (byte) ((x) & 0xff);
+ WriteBytes(R, R$, i, 0, 4);
}
public static void WriteReal(RECORD1 R[], int R$, float x)
public static void WriteString(RECORD1 R[], int R$, byte x[])
{
- SYSTEM.TRAP(-3);
+ byte[][] i = new byte[1][];
+ i[0] = x;
+ WriteBytes(R, R$, i, 0, SYSTEM.LEN(x) + 1);
}
public static void WriteSet(RECORD1 R[], int R$, int x)
public static void WriteBytes(RECORD1 r[], int r$, byte[][] x, int x$, int n)
{
- SYSTEM.TRAP(-3);
+ RECORD1 rider = r[r$];
+ RandomAccessFile desc = rider.base.desc;
+
+ try
+ {
+ rider.base.SetActive(rider);
+ desc.write(x[x$], 0, n);
+ rider.position += n;
+ }
+ catch(IOException e)
+ {
+ rider.res[0] = n;
+ rider.eof[0] = true;
+ }
}
public static void BEGIN()