Java Utililty Methods RandomAccessFile Read

List of utility methods to do RandomAccessFile Read

Description

The list of methods to do RandomAccessFile Read are organized into topic(s).

Method

HashMapread_structdesc(final RandomAccessFile raf)
reastructdesc
HashMap<String, Object> structdesc = new HashMap<>();
int structstart = read_long(raf);
if (structstart != 9) {
    throw new Exception("STRUCTSTART should be 9");
structdesc.put("name", read_string(raf));
int predef = read_long(raf);
structdesc.put("ntags", read_long(raf));
...
HashMapread_tagdesc(RandomAccessFile raf)
reatagdesc
HashMap<String, Object> tagdesc = new HashMap<>();
tagdesc.put("offset", read_long(raf));
if ((int) tagdesc.get("offset") == -1) {
    tagdesc.put("offset", read_uint64(raf));
tagdesc.put("typecode", read_long(raf));
int tagflags = read_long(raf);
tagdesc.put("array", (tagflags & 4) == 4);
...
HashMapread_typedesc(final RandomAccessFile raf)
reatypedesc
HashMap<String, Object> typedesc = new HashMap<>();
typedesc.put("typecode", read_long(raf));
typedesc.put("varflags", read_long(raf));
if (2 == ((int) typedesc.get("varflags") & 2)) {
    throw new Exception("System variables not implemented");
typedesc.put("array", ((int) typedesc.get("varflags") & 4) == 4);
typedesc.put("structure", ((int) typedesc.get("varflags") & 32) == 32);
...
shortread_UnsignedByte(RandomAccessFile raf)
Reads a Byte (-128 to 127).
byte[] data = new byte[1];
byte byteData = -1;
try {
    raf.read(data);
    ByteBuffer bb = ByteBuffer.allocate(data.length);
    bb.put(data);
    return getUnsignedByte(bb);
} catch (IOException e) {
...
bytereadAByte(ReadableByteChannel readChannel)
read A Byte
byte[] tmp = new byte[1];
if (readChannel == null) {
    throw new NullPointerException("Buffer exhausted and read channel is null, cannot continue");
int read = readChannel.read(ByteBuffer.wrap(tmp));
if (read < 0) {
    throw new IOException("Channel abruptly ended while expecting more data.");
return tmp[0];
ListreadFile(File f)
read File
err = new File(f.getParent() + "/neispravni_inventarni_brojevi.txt");
List<String> retVal = new ArrayList<String>();
try {
    errwriter = new PrintWriter(err);
    RandomAccessFile in = new RandomAccessFile(f, "r");
    String line;
    while ((line = in.readLine()) != null) {
        String invBr = parseLine(line);
...
byte[]readFile(File file)
read File
RandomAccessFile raf = new RandomAccessFile(file, "r");
byte[] ret = new byte[(int) raf.length()];
raf.read(ret);
raf.close();
return ret;
StringreadFile(File file)
read File
RandomAccessFile f = new RandomAccessFile(file, "r");
try {
    long longlength = f.length();
    int length = (int) longlength;
    if (length != longlength) {
        throw new IOException("File size >= 2 GB");
    byte[] data = new byte[length];
...
StringreadFile(final File file)
Reads and returns all content within the supplied file.
byte[] byteContent;
RandomAccessFile in = new RandomAccessFile(file, "r");
try {
    byteContent = new byte[(int) in.length()];
    in.readFully(byteContent);
} finally {
    try {
        in.close();
...
StringreadFile(String absoluteFileName)
Fills the contents of the file given to a String
File file = new File(absoluteFileName);
byte buffer[] = null;
RandomAccessFile raf = null;
try {
    raf = new RandomAccessFile(absoluteFileName, "r");
    int fileSize = (int) file.length();
    buffer = new byte[fileSize];
    raf.read(buffer, 0, fileSize);
...