// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3)
// Source File Name: RootInputStream.java
package hep.rootio.implementation;
import hep.rootio.*;
import java.io.*;
import java.util.Hashtable;
// Referenced classes of package hep.rootio.implementation:
// RootByteArrayInputStream, RootRandomAccessFile, AbstractRootObject
public class RootInputStream extends DataInputStream
implements RootInput
{
public RootInputStream(RootByteArrayInputStream in, RootRandomAccessFile raf)
{
super(in);
readMap = new Hashtable();
pos = 0L;
this.raf = raf;
}
public String readString()
throws IOException
{
return readString(((DataInput) (this)));
}
public String readNullTerminatedString(int maxLength)
throws IOException
{
return readNullTerminatedString(((DataInput) (this)), maxLength);
}
public int readVersion()
throws IOException
{
return readVersion(((RootInput) (this)), null);
}
public int readVersion(AbstractRootObject obj)
throws IOException
{
return readVersion(((RootInput) (this)), obj);
}
public int readArray(int data[])
throws IOException
{
return readArray(((RootInput) (this)), data);
}
public int readArray(byte data[])
throws IOException
{
return readArray(((RootInput) (this)), data);
}
public int readArray(float data[])
throws IOException
{
return readArray(((RootInput) (this)), data);
}
public int readArray(double data[])
throws IOException
{
return readArray(((RootInput) (this)), data);
}
public void checkLength(AbstractRootObject obj)
throws IOException
{
checkLength(((RootInput) (this)), obj);
}
public RootObjectRepresentation readObject(String type)
throws IOException
{
return readObject(((RootInput) (this)), type);
}
public RootObjectRepresentation readObjectRef()
throws IOException
{
return readObjectRef(((RootInput) (this)), readMap);
}
public RootClassFactory getFactory()
{
return raf.getFactory();
}
public RootRandomAccessFile getRAF()
{
return raf;
}
public long getPosition()
{
return ((RootByteArrayInputStream)super.in).getPosition();
}
public void setPosition(long pos)
{
((RootByteArrayInputStream)super.in).setPosition(pos);
}
static String readString(DataInput in)
throws IOException
{
int l = in.readByte();
byte data[] = new byte[l];
for(int i = 0; i < l; i++)
data[i] = in.readByte();
return new String(data);
}
static String readNullTerminatedString(DataInput in, int maxLength)
throws IOException
{
int actualLength = maxLength - 1;
byte data[] = new byte[maxLength];
for(int i = 0; i < maxLength; i++)
{
data[i] = in.readByte();
if(data[i] != 0)
continue;
actualLength = i;
break;
}
return new String(data, 0, actualLength);
}
static int readVersion(RootInput in, AbstractRootObject obj)
throws IOException
{
int version = in.readShort();
if((version & 0x4000) == 0)
return version;
int byteCount = ((version & 0x3fff) << 16) + in.readUnsignedShort();
if(obj != null)
obj.setExpectedLength(in.getPosition(), byteCount);
return in.readShort();
}
static int readArray(RootInput in, int data[])
throws IOException
{
int n = in.readInt();
for(int i = 0; i < n; i++)
data[i] = in.readInt();
return n;
}
static int readArray(RootInput in, byte data[])
throws IOException
{
int n = in.readInt();
for(int i = 0; i < n; i++)
data[i] = in.readByte();
return n;
}
static int readArray(RootInput in, float data[])
throws IOException
{
int n = in.readInt();
for(int i = 0; i < n; i++)
data[i] = in.readFloat();
return n;
}
static int readArray(RootInput in, double data[])
throws IOException
{
int n = in.readInt();
for(int i = 0; i < n; i++)
data[i] = in.readDouble();
return n;
}
static void checkLength(RootInput in, AbstractRootObject obj)
throws IOException
{
obj.checkLength(in.getPosition());
}
static RootObjectRepresentation readObject(RootInput in, String type)
throws IOException
{
try
{
RootObjectRepresentation obj = in.getFactory().create(type).newInstance();
obj.read(in);
return obj;
}
catch(RootClassNotFound x)
{
throw new IOException("Could not find class " + x.getClassName());
}
}
static RootObjectRepresentation readObjectRef(RootInput in, Hashtable map)
throws IOException
{
long objStartPos = in.getPosition();
int fVersion = 0;
long startpos = 0L;
int bcnt = in.readInt();
int tag;
if((bcnt & kByteCountMask) == 0 || bcnt == kNewClassTag)
{
tag = bcnt;
bcnt = 0;
} else
{
fVersion = 1;
startpos = in.getPosition();
tag = in.readInt();
}
if((tag & kClassMask) == 0)
{
if(tag == 0)
return null;
Object obj = map.get(new Long(tag));
if(obj == null || !(obj instanceof RootObjectRepresentation))
throw new IOException("Invalid tag found " + tag);
else
return (RootObjectRepresentation)obj;
}
RootClass rootClass;
RootObjectRepresentation obj;
if(tag == kNewClassTag)
try
{
String className = in.readNullTerminatedString(80);
rootClass = in.getFactory().create(className);
if(fVersion > 0)
map.put(new Long(startpos + (long)kMapOffset), rootClass);
else
map.put(new Long(map.size() + 1), rootClass);
obj = rootClass.newInstance();
if(fVersion > 0)
map.put(new Long(objStartPos + (long)kMapOffset), obj);
else
map.put(new Long(map.size() + 1), obj);
obj.read(in);
return obj;
}
catch(RootClassNotFound x)
{
throw new IOException("Class not found during object read: " + x.getClassName());
}
tag &= ~kClassMask;
Object cls = map.get(new Long(tag));
if(cls == null || !(cls instanceof RootClass))
throw new IOException("Invalid object tag " + tag);
rootClass = (RootClass)cls;
obj = rootClass.newInstance();
if(fVersion > 0)
{
Long offset = new Long(objStartPos + (long)kMapOffset);
map.put(offset, obj);
} else
{
map.put(new Long(map.size() + 1), obj);
}
obj.read(in);
return obj;
}
private Hashtable readMap;
private long pos;
private RootRandomAccessFile raf;
private static int kByteCountMask = 0x40000000;
private static int kNewClassTag = -1;
private static int kClassMask = 0x80000000;
private static int kMapOffset = 2;
}
Ads help maintain this website.