Java Utililty Methods DataInputStream Read

List of utility methods to do DataInputStream Read

Description

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

Method

byte[]readBytesArray(DataInputStream dis)
read Bytes Array
try {
    int len = dis.readInt();
    if (len > 0) {
        byte[] ret = new byte[len];
        int read = dis.read(ret);
        if (read < len) {
            throw new RuntimeException("Corrupt " + RENDER_GEOMETRY_FILE_EXT
                    + " file; found array which is shorter than declated.");
...
byte[]readFromFile(File file)
read From File
long fileSize = file.length();
byte[] fileData = new byte[(int) fileSize];
FileInputStream fileIn;
DataInputStream dataIn;
int offset = 0;
int numRead = 0;
try {
    fileIn = new FileInputStream(file);
...
ArrayListreadFromFileToLineArray(File file)
read From File To Line Array
System.out.println("Debug: full input File Name " + file);
ArrayList<String> lines = new ArrayList<String>();
FileInputStream fstream = null;
try {
    fstream = new FileInputStream(file);
} catch (FileNotFoundException e) {
    e.printStackTrace();
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
try {
    while ((strLine = br.readLine()) != null) {
        lines.add(strLine);
    in.close();
} catch (IOException e) {
    e.printStackTrace();
return lines;
voidsaveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out)
save Double Matrix From Binary
out.println(rows + " " + cols);
for (int i = 0; i < rows; i++) {
    double[] row = readDoubleArrayFromFileBinary(reader, cols);
    for (int j = 0; j < cols; j++) {
        out.print(row[j]);
        if (j != cols - 1) {
            out.print(" ");
    out.println();