X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=rtl%2Fjava%2FFiles.java;h=c201940c21cbb37cc41a3f0b85ee546288cea4b9;hb=317e2eb03b343f9d753990e6ed8386fd4effca60;hp=5fe0074ca6293714b95895c070a78113ee14fcbe;hpb=0f382f6efef254a295e71dc82ddd0f87b95aaddd;p=dsw-obn.git diff --git a/rtl/java/Files.java b/rtl/java/Files.java index 5fe0074..c201940 100644 --- a/rtl/java/Files.java +++ b/rtl/java/Files.java @@ -99,8 +99,9 @@ class Files 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) @@ -110,14 +111,20 @@ class Files 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; } @@ -351,17 +358,38 @@ class Files public static void Write(RECORD1 r[], int r$, byte x) { - SYSTEM.TRAP(-3); + RECORD1 rider = r[r$]; + RandomAccessFile desc = rider.base.desc; + + try + { + rider.base.SetActive(rider); + desc.write(x); + rider.position += 1; + } + catch(IOException e) + { + rider.res[0] = 1; + rider.eof[0] = true; + } } public static void WriteInt(RECORD1 R[], int R$, short x) { - SYSTEM.TRAP(-3); + byte[][] i = new byte[1][2]; + i[0][0] = (byte) ((x >>> 8) & 0xff); + i[0][1] = (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][0] = (byte) ((x >>> 24) & 0xff); + i[0][1] = (byte) ((x >>> 16) & 0xff); + i[0][2] = (byte) ((x >>> 8) & 0xff); + i[0][3] = (byte) ((x) & 0xff); + WriteBytes(R, R$, i, 0, 4); } public static void WriteReal(RECORD1 R[], int R$, float x) @@ -381,7 +409,9 @@ class Files 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)); } public static void WriteSet(RECORD1 R[], int R$, int x) @@ -396,7 +426,20 @@ class Files 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()