fileinfo.java
来自「一个简单的visio程序。」· Java 代码 · 共 491 行
JAVA
491 行
package HPCore.stdstmt;
import java.io.*;
import HPCore.Exception.*;
public class fileinfo
{
File f=null;
RandomAccessFile raf = null;
DataInputStream dis = null;
//FileOutputStream raf2 = null;
//int FNum=0;/* start from 1......*/
//properties...
public String name ;
public int mode ;
public short fnum ;
public int reclen ;
public boolean state = true ;
public boolean pos = false ;
public int access ;
public int flock ;// phmode ;
public long length ; // filelength
//spc(),tab() for print statement
public int width = 0 ; // linelength
public int spcnum = 0 ; // spc(n) spcnum == n
public int tabnum = 0 ; // tab(n) tabnum == n
public boolean wreturn = true;
public boolean ishttp = false;
public long offset = 0 ; ;
public fileinfo(RandomAccessFile af0, File f0) throws HpException
{
f = f0;
raf = af0;
ishttp = false;
try{
length = raf.length();
wreturn = true;
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public fileinfo(DataInputStream af0) throws HpException
{
dis = af0;
ishttp = true;
offset = 0;
}
public long Length() throws HpException
{
long l = 0;
try{
if (raf != null)
l = raf.length();
else
l = length;
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return l;
}
public void vbSeek(long seekpos) throws HpException
{
try{
if (raf != null)
{
raf.seek (seekpos);
offset = raf.getFilePointer();
}
else
{
dis.mark((int)seekpos);
dis.reset();
offset = seekpos;
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public long GetFilePointer() throws HpException
{
long l = 0;
try{
if (raf != null)
l = raf.getFilePointer();
else
l = offset;
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return l;
}
public void reset() throws HpException
{
try{
if (dis != null && ishttp)
dis.reset();
}catch(IOException ioex)
{
throw new HpException(5,ioex.getMessage());
}
}
public void SkipBytes(int num) throws HpException
{
long pf = 0;
try{
if (raf != null)
{
pf = raf.getFilePointer();
if (num + (int)pf < length)
raf.skipBytes(num);
else
throw new HpException(4,"End of file"); //return error
offset = raf.getFilePointer();
}
else
{
pf = offset;
if (num + (int)pf < length)
raf.skipBytes(num);
else
throw new HpException(4,"End of file"); //return error
offset = offset+num;
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final int Read() throws HpException
{
int n = 0;
try{
if (raf != null)
{
n = raf.read();
offset = raf.getFilePointer();
}
else
{
n = dis.read();
offset += 1;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return n;
}
public final short ReadShort() throws HpException
{
short n = 0;
try{
if (raf != null)
{
n = raf.readShort();
offset = raf.getFilePointer();
}
else
{
n = dis.readShort();
offset += 2;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return n;
}
public final int ReadUnsignedShort() throws HpException
{
int n = 0;
try{
if (raf != null)
{
n = raf.readUnsignedShort();
offset = raf.getFilePointer();
}
else
{
n = dis.readUnsignedShort();
offset += 2;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return n;
}
public final int ReadInt() throws HpException
{
int vint = 0;
try{
if (raf != null)
{
vint = raf.readInt();
offset = raf.getFilePointer();
}
else
{
vint = dis.readInt();
offset += 4;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return vint;
}
public final long ReadLong() throws HpException
{
long vlng = 0;
try{
if (raf != null)
{
vlng = raf.readLong();
offset = raf.getFilePointer();
}
else
{
vlng = dis.readLong();
offset += 8;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return vlng;
}
public final float ReadFloat() throws HpException
{
float vflt = 0;
try{
if (raf != null)
{
vflt = raf.readFloat();
offset = raf.getFilePointer();
}
else
{
vflt = dis.readFloat();
offset += 4;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return vflt;
}
public final double ReadDouble() throws HpException
{
double vdbl = 0;
try{
if (raf != null)
{
vdbl = raf.readDouble();
offset = raf.getFilePointer();
}
else
{
vdbl = dis.readDouble();
offset += 8;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return vdbl;
}
public final int ReadUnsignedByte() throws HpException
{
int ch = 0;
try{
if (raf != null)
{
ch = raf.readUnsignedByte();
offset = raf.getFilePointer();
}
else
{
ch = dis.readUnsignedByte();
offset += 1;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return ch;
}
public final byte ReadByte() throws HpException
{
byte b = 0 ;
try{
if (raf != null)
{
b = raf.readByte();
offset = raf.getFilePointer();
}
else
{
b = dis.readByte();
offset += 1;
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return b;
}
public final String ReadLine() throws HpException
{
String str = null;
try{
if (raf != null)
{
str = raf.readLine();
offset = raf.getFilePointer();
}
}catch (IOException ioex){
throw new HpException(5,ioex.getMessage());
}
return str;
}
public final void WriteByte(int v) throws HpException
{
try{
if (raf != null)
{
raf.writeByte(v);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final void WriteDouble(double v) throws HpException
{
try{
if (raf != null)
{
raf.writeDouble(v);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final void WriteBytes(String str) throws HpException
{
try{
if (raf != null)
{
raf.writeBytes(str);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final void WriteLong(long ch) throws HpException
{
try{
if (raf != null)
{
int i1 = (int)ch;
i1 = ((i1 & 0xff) << 24) + ((i1 & 0xff00) << 8) +
((i1 & 0xff0000) >> 8) + ((i1 >> 24) & 0xff);
raf.writeInt(i1);
int i2 = (int)(ch >> 32);
i2 = ((i2 & 0xff) << 24) + ((i2 & 0xff00) << 8) +
((i2 & 0xff0000) >> 8) + ((i2 >> 24) & 0xff);
raf.writeInt(i2);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final void WriteInt(int v) throws HpException
{
try{
if (raf != null)
{
raf.writeInt(v);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final void WriteFloat(float v) throws HpException
{
try{
if (raf != null)
{
raf.writeFloat(v);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public final void WriteShort(int v) throws HpException
{
try{
if (raf != null)
{
raf.writeShort(v);
offset = raf.getFilePointer();
}
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public void close() throws HpException
{
try{
if (raf != null)
{
raf.close();
}
else
dis.close();
}catch(IOException ioex){
throw new HpException(5,ioex.getMessage());
}
}
public void kill () throws HpException
{
try{
if (f != null && f.exists())
f.delete();
}catch(SecurityException e){
throw new HpException(17,"Can't perform requested operation");//"File can't delete.");
}catch(Exception io){
throw new HpException(53,"File not found");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?