Example usage for java.io FileInputStream close

List of usage examples for java.io FileInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

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

Usage

From source file:de.jwi.ftp.FTPUploader.java

private static String uploadFile(FTPClient ftp, String ftpServerPath, File f) throws IOException {
    String name = f.getName();/*from   w  ww.  jav  a  2s  .  c  o m*/
    String rcs = "error";

    FileInputStream fi = new FileInputStream(f);

    boolean rc = false;
    try {
        System.out.println(f);
        System.out.println(ftpServerPath + " " + name);
        rc = ftp.storeFile(name, fi);
        rcs = rc ? "" : rcs;
    } finally {
        fi.close();
    }
    return rcs;
}

From source file:com.aerofs.baseline.config.Configuration.java

@SuppressWarnings("unchecked")
public static <C extends Configuration> C loadYAMLConfigurationFromFile(Class<?> derived,
        String configurationFile) throws IOException {
    FileInputStream in = null;

    try {/*from w w w . j  a  v a  2s.c om*/
        in = new FileInputStream(configurationFile);
        return Configuration.loadYAMLConfigurationFromStream(derived, in);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                LOGGER.warn("fail close input stream for {}", configurationFile, e);
            }
        }
    }
}

From source file:Main.java

/**
 * Parses a file and generates an XML document.
 * @param file//from   w  w  w. j  av a2 s.co m
 * @return An XML doucument.
 */
public static Document parseXML(File file) {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(file);
        return parseXML(fis);
    } catch (Exception e) {
        throw new RuntimeException("Failed to open XML file:" + file, e);
    } finally {
        try {
            fis.close();
        } catch (Exception e) {
        }
    }
}

From source file:kilim.tools.FlowAnalyzer.java

private static void analyzeClass(String className, Detector detector) {
    try {//www. ja v a 2  s  .  com
        pn("-------------------------------------------------");
        pn("Class: " + className);
        //            System.out.flush();
        ClassFlow cf = null;
        if (className.endsWith(".class")) {
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(className);
                cf = new ClassFlow(fis, detector);
            } finally {
                if (fis != null) {
                    fis.close();
                }
            }
        }
        if (cf == null) {
            cf = new ClassFlow(className, detector);
        }
        ArrayList<MethodFlow> flows = cf.analyze(true);
        for (MethodFlow flow : flows) {
            reportFlow(flow, className);
        }
    } catch (IOException e) {
        pn("##################################################");
        stackTrace(e);
    } catch (Throwable ie) {
        pn("##################################################");
        stackTrace(ie);
    }
}

From source file:Neo4JDataImporter.java

public static void importData(GraphDatabaseService dbApi, Node root, File file) throws Exception {
    Transaction tr = dbApi.beginTx();/*from w ww  .  j av  a  2  s  .  c o m*/
    try {
        FileInputStream is = new FileInputStream(file);
        DiscoveredDeviceData discoveryManagerType = null;
        try {
            discoveryManagerType = JaxbMarshalar.unmarshal(DiscoveredDeviceData.class, is);
        } finally {
            is.close();
        }
        importDiscoveredDeviceData(dbApi, root, discoveryManagerType);
        System.out.println("before to commit transaction");
        tr.success();
        System.out.println("after to commit transaction");
    } catch (Exception e) {
        e.printStackTrace();
        tr.failure();
    } finally {
        System.out.println("before to finish transaction");
        tr.finish();
        System.out.println("after to finish transaction");
    }
}

From source file:com.twitter.ambrose.util.JSONUtil.java

public static String readFile(String path) throws IOException {
    FileInputStream stream = new FileInputStream(new File(path));
    try {/*  w w  w .j  a  v  a2s  .  c om*/
        FileChannel fc = stream.getChannel();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        return Charset.defaultCharset().decode(bb).toString();
    } finally {
        stream.close();
    }
}

From source file:QueryDB.java

/**
     * Gets a connection from the properties specified in the file database.properties
     * @return the database connection/* w  w w  . j a  v  a 2s. co m*/
     */
    public static Connection getConnection() throws SQLException, IOException {
        Properties props = new Properties();
        FileInputStream in = new FileInputStream("database.properties");
        props.load(in);
        in.close();

        String drivers = props.getProperty("jdbc.drivers");
        if (drivers != null)
            System.setProperty("jdbc.drivers", drivers);
        String url = props.getProperty("jdbc.url");
        String username = props.getProperty("jdbc.username");
        String password = props.getProperty("jdbc.password");

        return DriverManager.getConnection(url, username, password);
    }

From source file:com.pongasoft.util.io.IOUtils.java

@SuppressWarnings("unchecked")
public static <T> T deserializeFromFile(File file) throws IOException, ClassNotFoundException {
    if (file == null)
        return null;

    FileInputStream fis = new FileInputStream(file);
    try {/*from w  ww . j  a v  a2  s  . c  o m*/
        return (T) deserialize(new BufferedInputStream(fis));
    } finally {
        fis.close();
    }
}

From source file:com.littcore.io.util.ZipUtils.java

/**
 * ?/*from ww  w .j  a va2 s  .c o  m*/
 * @param files 
 * @param targetFileNamePath 
 * @throws IOException
 */
public static void batchZip(File[] files, String targetFileNamePath) throws IOException {
    //?
    CheckedOutputStream cs = new CheckedOutputStream(new FileOutputStream(targetFileNamePath), new CRC32());
    //zip?
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(cs));
    File srcFile = null;
    for (int i = 0; i < files.length; i++) {
        srcFile = files[i];
        out.putNextEntry(new ZipEntry(srcFile.getName()));
        FileInputStream in = new FileInputStream(srcFile);
        int len;
        byte[] buf = new byte[BUFFERED_SIZE];
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.closeEntry();
        in.close();
    }
    out.close();
}

From source file:Main.java

/**
 * Simple copy.  Horrible performance for large files.
 * Good performance for alphabets./*from www. ja v  a2s  . c  o m*/
 */
public static void copyFile(File source, File dest) throws Exception {
    FileInputStream fis = new FileInputStream(source);
    try {
        FileOutputStream fos = new FileOutputStream(dest);
        try {
            int read = fis.read();
            while (read != -1) {
                fos.write(read);
                read = fis.read();
            }
        } finally {
            fos.close();
        }
    } finally {
        fis.close();
    }
}