2 // Body of GPFiles interface.
3 // This file implements the code of the GPFiles.cp file.
11 import CP
.GPFiles
.GPFiles
.*;
13 public class GPBinFiles
{
15 public static int length(GPBinFiles_FILE cpf
) {
16 return (int) cpf
.length
;
19 public static GPBinFiles_FILE
findLocal(char[] fileName
)
21 String currDir
= System
.getProperty("user.dir");
22 GPBinFiles_FILE cpf
= new GPBinFiles_FILE();
23 cpf
.f
= new File(currDir
, CP
.CPJ
.CPJ
.MkStr(fileName
));
24 if (!cpf
.f
.exists()) {
27 cpf
.rf
= new RandomAccessFile(cpf
.f
,"r");
28 cpf
.length
= cpf
.rf
.length();
33 public static GPBinFiles_FILE
findOnPath(char[] pathName
,
34 char[] fileName
) throws IOException
{
36 // Use MkStr, to trim space from end of char arrray.
38 String pName
= CP
.CPJ
.CPJ
.MkStr(pathName
);
39 String fName
= CP
.CPJ
.CPJ
.MkStr(fileName
);
42 String thisPath
= System
.getProperty(pName
);
43 GPBinFiles_FILE cpf
= new GPBinFiles_FILE();
44 boolean found
= false;
45 boolean pathFinished
= false;
46 int length
= thisPath
.length();
47 int nextPathStart
= -1, nextPathEnd
= -1;
49 while (!found
&& !pathFinished
) {
50 nextPathStart
= nextPathEnd
+ 1;
51 nextPathEnd
= thisPath
.indexOf(CP
.GPFiles
.GPFiles
.pathSep
,nextPathStart
);
54 nextDir
= thisPath
.substring(nextPathStart
,nextPathEnd
);
55 cpf
.f
= new File(nextDir
,fName
);
56 found
= cpf
.f
.exists();
57 pathFinished
= nextPathEnd
>= length
;
60 cpf
.rf
= new RandomAccessFile(cpf
.f
,"r");
61 cpf
.length
= cpf
.rf
.length();
68 public static char[] getFullPathName(GPBinFiles_FILE cpf
) {
69 return cpf
.f
.getPath().toCharArray();
72 public static GPBinFiles_FILE
openFile(char[] fileName
)throws IOException
{
73 GPBinFiles_FILE cpf
= new GPBinFiles_FILE();
74 cpf
.f
= new File(CP
.CPJ
.CPJ
.MkStr(fileName
));
75 if (!cpf
.f
.exists()) {
78 cpf
.rf
= new RandomAccessFile(cpf
.f
,"rw");
79 cpf
.length
= cpf
.rf
.length();
84 public static GPBinFiles_FILE
openFileRO(char[] fileName
)throws IOException
{
85 GPBinFiles_FILE cpf
= new GPBinFiles_FILE();
86 cpf
.f
= new File(CP
.CPJ
.CPJ
.MkStr(fileName
));
87 if (!cpf
.f
.exists()) {
90 cpf
.rf
= new RandomAccessFile(cpf
.f
,"r");
91 cpf
.length
= cpf
.rf
.length();
96 public static void CloseFile(GPBinFiles_FILE cpf
) throws IOException
{
100 public static GPBinFiles_FILE
createFile(char[] fileName
)throws IOException
{
101 GPBinFiles_FILE cpf
= new GPBinFiles_FILE();
102 cpf
.f
= new File(CP
.CPJ
.CPJ
.MkStr(fileName
));
103 cpf
.rf
= new RandomAccessFile(cpf
.f
,"rw");
106 // cpf.length = cpf.rf.length();
110 public static GPBinFiles_FILE
createPath(char[] fileName
)throws IOException
{
111 String fName
= CP
.CPJ
.CPJ
.MkStr(fileName
);
112 int ix
= fName
.lastIndexOf(File
.separatorChar
);
114 File path
= new File(fName
.substring(0,ix
));
115 if (!path
.exists()) { boolean ok
= path
.mkdirs(); }
117 GPBinFiles_FILE cpf
= new GPBinFiles_FILE();
118 cpf
.f
= new File(fName
);
119 cpf
.rf
= new RandomAccessFile(cpf
.f
,"rw");
122 // cpf.length = cpf.rf.length();
126 public static boolean EOF(GPBinFiles_FILE cpf
) throws IOException
{
127 return cpf
.rf
.getFilePointer() >= cpf
.length
;
130 public static int readByte(GPBinFiles_FILE cpf
) throws IOException
{
131 return cpf
.rf
.readUnsignedByte();
134 public static int readNBytes(GPBinFiles_FILE cpf
, byte[] buff
,
135 int numBytes
) throws IOException
{
136 return cpf
.rf
.read(buff
,0,numBytes
);
139 public static void WriteByte(GPBinFiles_FILE cpf
,int b
) throws IOException
{
143 public static void WriteNBytes(GPBinFiles_FILE cpf
,byte[] buff
,
144 int numBytes
) throws IOException
{
145 cpf
.rf
.write(buff
,0,numBytes
);