Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.FileInputStream;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * Helper method
     * <p/>
     * Used by {@link OfflineUtilities#getUncomplessedOfflineFile(FileInputStream)}
     * Takes in the input stream for the offline storage and reads the contents into a byte array
     *
     * @param file The input stream for the offline storage {@see android.content.Context#openFileInput(String)}
     * @return The byte array representation of the offline file
     * @throws IOException If  something goes wrong with the file reading
     */
    private static byte[] fileToArr(FileInputStream file) throws IOException {
        List<Byte> tripFile = new ArrayList<>();
        for (byte b; (b = (byte) file.read()) != -1;) {
            tripFile.add(b);
        }
        byte[] tripBytes = new byte[tripFile.size()];
        int pos = 0;
        for (Byte b : tripFile) {
            tripBytes[pos++] = b.byteValue();
        }
        return tripBytes;
    }
}