Example usage for java.io DataInputStream close

List of usage examples for java.io DataInputStream close

Introduction

In this page you can find the example usage for java.io DataInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:org.apache.accumulo.test.util.SerializationUtil.java

public static void deserializeWritable(Writable writable, InputStream inputStream) {
    Objects.requireNonNull(writable);
    Objects.requireNonNull(inputStream);
    DataInputStream in = null;
    try {/*from  w  ww  .  jav  a 2  s .c o m*/
        in = new DataInputStream(inputStream);
        writable.readFields(in);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (IOException e) {
                log.error("cannot close", e);
            }
    }
}

From source file:org.beanfuse.archiver.ZipUtils.java

public static File zip(List fileNames, String zipPath, String encoding) {
    try {/*ww  w.  java  2 s .  co m*/
        FileOutputStream f = new FileOutputStream(zipPath);
        ZipOutputStream out = new ZipOutputStream(new DataOutputStream(f));
        out.setEncoding(encoding);
        for (int i = 0; i < fileNames.size(); i++) {
            DataInputStream in = new DataInputStream(new FileInputStream(fileNames.get(i).toString()));
            out.putNextEntry(new org.apache.tools.zip.ZipEntry(
                    StringUtils.substringAfterLast(fileNames.get(i).toString(), File.separator)));
            int c;
            while ((c = in.read()) != -1) {
                out.write(c);
            }
            in.close();
        }
        out.close();
        return new File(zipPath);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.gNova.circularFP.Fingerprinter.java

private static List<String> readSmartsFile() {
    ArrayList<String> smarts = new ArrayList<String>();
    try {//ww  w .ja  v  a  2  s  . c  o m
        FileInputStream fstream = new FileInputStream(smaFile);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        while ((strLine = br.readLine()) != null) {
            if (!strLine.startsWith("#") && strLine.trim().length() > 0) {
                smarts.add(strLine);
            }
        }
        in.close();
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        System.exit(0);
    }
    return smarts;
}

From source file:Main.java

public static int[] readBin83PtIndex(String dir, String fileName) {
    int i = 0;//from   ww w.j a v a 2 s .c om
    int x = 0;
    int[] tab = new int[83];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readInt();
        while (true) {
            tab[i] = x;
            i++;
            x = in.readInt();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:Main.java

public static int[] readBinIntArray(String dir, String fileName, int size) {
    int x;/*from   w  w w.j  a  va  2  s  .  c o m*/
    int i = 0;
    int[] tab = new int[size];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readInt();
        while (true) {
            tab[i] = x;
            i++;
            x = in.readInt();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:Main.java

public static float[] readBinFloat(String dir, String fileName, int size) {
    float x;//  w w  w  . j  a v  a 2  s. co  m
    int i = 0;
    float[] tab = new float[size];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readFloat();
        while (i < size) {
            tab[i] = x;
            i++;
            x = in.readFloat();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:Main.java

public static float[] readBinShapeArray(String dir, String fileName, int size) {
    float x;//w  ww . j ava2  s . c o  m
    int i = 0;
    float[] tab = new float[size];

    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        //read first x
        x = in.readFloat();
        while (true) {
            tab[i] = x;
            i++;
            x = in.readFloat();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:Main.java

public static String[] getUvValues() {
    ArrayList<String> value = new ArrayList<String>();

    try {//w w  w  . j av  a  2 s. c om
        // Open the file that is the first
        // command line parameter
        FileInputStream fstream = null;
        File f = new File("/sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels");
        if (f.exists()) {
            fstream = new FileInputStream("/sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels");
        } else {
            File ff = new File("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
            if (ff.exists()) {
                fstream = new FileInputStream("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
            }
        }
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        // Read File Line By Line
        while ((strLine = br.readLine()) != null) {
            strLine = strLine.trim();

            if ((strLine.length() != 0)) {
                String[] val = strLine.split("\\s+");
                value.add(val[1]);
            }

        }
        // Close the input stream
        in.close();
    } catch (Exception e) {// Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
    String[] values = new String[value.size() - 1];
    values = value.toArray(values);
    return values;
}

From source file:Main.java

/**
 * Read the featureVector_Shape.dat file.
 * Build the double array and return it.
 * k : number of rows//from ww w .  jav  a  2 s . c  o  m
 * n : number of columns
 */
public static float[][] readBinFloatDoubleArray(String dir, String fileName, int k, int n) {
    float[][] array2D = new float[k][n];
    float x;
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < n; j++) {
                x = in.readFloat();
                array2D[i][j] = x;
            }
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return array2D;
}

From source file:org.apache.carbondata.core.datastore.CompressdFileTest.java

private static String readCompressed(String path) throws Exception {
    DataInputStream fileReader = null;
    BufferedReader bufferedReader = null;
    String readLine = null;/*from www  . j  av a2s  .c o m*/

    try {
        fileReader = FileFactory.getDataInputStream(path, FileType.HDFS);
        bufferedReader = new BufferedReader(
                new InputStreamReader(fileReader, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
        readLine = bufferedReader.readLine();
    } finally {
        if (null != fileReader) {
            fileReader.close();
        }

        if (null != bufferedReader) {
            bufferedReader.close();
        }
    }
    return readLine;
}