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:MSUmpire.SpectrumParser.DIA_Setting.java

public static DIA_Setting ReadDIASettingSerialization(String filepath) {
    if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser")
            .exists()) {//www . j a  va  2s .  co  m
        return null;
    }
    try {
        Logger.getRootLogger().debug("Reading DIA setting from file:" + FilenameUtils.getFullPath(filepath)
                + FilenameUtils.getBaseName(filepath) + "_diasetting.ser...");

        FileInputStream fileIn = new FileInputStream(
                FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        DIA_Setting setting = (DIA_Setting) in.readObject();
        in.close();
        fileIn.close();
        return setting;

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }
}

From source file:FileUtil.java

public final static byte[] load(FileInputStream fin) {
    byte readBuf[] = new byte[512 * 1024];

    try {// ww w . j a  va2s.c  o  m
        ByteArrayOutputStream bout = new ByteArrayOutputStream();

        int readCnt = fin.read(readBuf);
        while (0 < readCnt) {
            bout.write(readBuf, 0, readCnt);
            readCnt = fin.read(readBuf);
        }

        fin.close();

        return bout.toByteArray();
    } catch (Exception e) {

        return new byte[0];
    }
}

From source file:org.processbase.ui.core.Constants.java

private static void load(File file) throws FileNotFoundException, IOException {

    FileInputStream fis = new FileInputStream(file);
    if (properties == null)
        properties = new Properties();
    properties.load(fis);/* w w  w  . j  a va 2s .  co m*/
    fis.close();
    TASKLIST_PAGE_URL = properties.getProperty("TASKLIST_PAGE_URL");
    //System.setProperty("org.ow2.bonita.api-type", properties.containsKey("org.ow2.bonita.api-type") ? properties.getProperty("org.ow2.bonita.api-type") : "EJB3");
    BONITA_EJB_ENV.put("org.ow2.bonita.api-type",
            properties.containsKey("org.ow2.bonita.api-type")
                    ? properties.getProperty("org.ow2.bonita.api-type")
                    : "EJB3");
    BONITA_EJB_ENV.put("java.naming.factory.initial", properties.getProperty("java.naming.factory.initial"));
    BONITA_EJB_ENV.put("java.naming.factory.url.pkgs", properties.getProperty("java.naming.factory.url.pkgs"));
    BONITA_EJB_ENV.put("java.naming.factory.state",
            properties.containsKey("java.naming.factory.state")
                    ? properties.getProperty("java.naming.factory.state")
                    : "");
    BONITA_EJB_ENV.put("java.naming.provider.url", properties.getProperty("java.naming.provider.bonitaurl"));
    BONITA_EJB_ENV.put("java.security.auth.login.config",
            properties.getProperty("java.security.auth.login.config"));
    BONITA_EJB_ENV.put("org.omg.CORBA.ORBInitialHost",
            properties.containsKey("org.omg.CORBA.ORBInitialHost")
                    ? properties.getProperty("org.omg.CORBA.ORBInitialHost")
                    : "localhost");
    BONITA_EJB_ENV.put("org.omg.CORBA.ORBInitialPort",
            properties.containsKey("org.omg.CORBA.ORBInitialPort")
                    ? properties.getProperty("org.omg.CORBA.ORBInitialPort")
                    : "23700");

    DL_GROUP = properties.containsKey("DL_GROUP") ? properties.getProperty("DL_GROUP") : "DOCUMENTS";
    BONITA_DOMAIN = properties.containsKey("BONITA_DOMAIN") ? properties.getProperty("BONITA_DOMAIN")
            : "default";
    APP_SERVER = properties.containsKey("APP_SERVER") ? properties.getProperty("APP_SERVER") : "GLASSFISH3";

    //BAM_DB_POOLNAME = properties.containsKey("BAM_DB_POOLNAME") ? properties.getProperty("BAM_DB_POOLNAME") : "jdbc/pbbam";
    //BAM_DB_DIALECT = properties.containsKey("BAM_DB_DIALECT") ? properties.getProperty("BAM_DB_DIALECT") : "org.hibernate.dialect.Oracle10gDialect";

    CUSTOM_UI_JAR_PATH = properties.containsKey("CUSTOM_UI_JAR_PATH")
            ? properties.getProperty("CUSTOM_UI_JAR_PATH")
            : "";
}

From source file:com.technofovea.packbsp.crawling.AssetAlternative.java

/**
 * Taking an array of alternative items, tests if there is a
 * @param items/*from ww  w  .ja v  a  2 s  .c  o  m*/
 * @return
 * @throws IOException
 */
public static CollisionType hasCustomCollision(List<AssetAlternative> items) throws IOException {
    //TODO same-hash in BSP+Archive is a bad idea since it means the map is not forward-compatible. Fix in future
    if (items.size() < 2) {
        // Nothing to even check against
        return CollisionType.NONE;
    }

    // Test if our first-level item collides with the first ARCHIVE-type things below it

    AssetAlternative topLevelItem = items.get(0);
    AssetAlternative archivedItem = null;
    for (int i = 1; i < items.size(); i++) {
        AssetAlternative next = items.get(i);
        if (next.getType().equals(Type.ARCHIVE)) {
            archivedItem = next;
            break;
        }
    }
    if (archivedItem == null) {
        // No secondary item was found that was an archive-type
        // Nothing relevant to collide with
        return CollisionType.NONE;
    }

    // Basic size check
    File diskFile = topLevelItem.getFile();
    File archiveFile = archivedItem.getFile();

    boolean sameSize = (diskFile.length() == archiveFile.length());
    boolean sameData = false;
    if (sameSize) {
        // Tougher check involving actual contents
        FileInputStream diskStream = new FileInputStream(diskFile);
        FileInputStream archiveStream = new FileInputStream(archiveFile);
        sameData = IOUtils.contentEquals(diskStream, archiveStream);
        diskStream.close();
        archiveStream.close();
    }

    if (sameData) {
        return CollisionType.DUPLICATE;
    } else {
        return CollisionType.CONFLICTING;
    }

}

From source file:Main.java

public static void divideFile() throws IOException {
    String path = "F:/ar/";
    String base = "phoneAttribution";
    String ext = ".db";

    int split = 800 * 1024;
    byte[] buf = new byte[1024];
    int num = 1;//from  www  .  j  av a  2  s  .  co m

    File inFile = new File(path + base + ext);
    FileInputStream fis = new FileInputStream(inFile);
    while (true) {
        FileOutputStream fos = new FileOutputStream(new File(path + base + num + ext));
        for (int i = 0; i < split / buf.length; i++) {
            int read = fis.read(buf);
            fos.write(buf, 0, buf.length);
            if (read < buf.length) {
                fis.close();
                fos.close();
                return;
            }
        }
        fos.close();
        num++;
    }
}

From source file:Main.java

public static String readFile(String path) throws IOException {
    FileInputStream stream = new FileInputStream(new File(path));
    String str = null;/* w  w  w  . j a  va 2 s .c  om*/
    try {
        FileChannel fc = stream.getChannel();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        /* Instead of using default, pass in a decoder. */
        str = Charset.defaultCharset().decode(bb).toString();
    } finally {
        stream.close();
    }
    return str;
}

From source file:Main.java

public static void copyFile(File src, File dest) throws IOException {
    FileOutputStream fileOut = null;
    FileInputStream fileIn = null;
    try {/*ww  w  .j av  a 2s . co m*/
        fileOut = new FileOutputStream(dest);
        fileIn = new FileInputStream(src);
        FileChannel inChannel = fileIn.getChannel();
        FileChannel outChannel = fileOut.getChannel();
        inChannel.transferTo(0, inChannel.size(), outChannel);
    } finally {
        if (fileIn != null) {
            fileIn.close();
        }
        if (fileOut != null) {
            fileOut.close();
        }
    }
}

From source file:org.apache.cxf.fediz.integrationtests.HolderOfKeyTest.java

private static Tomcat startServer(boolean idp, String port)
        throws ServletException, LifecycleException, IOException {
    Tomcat server = new Tomcat();
    server.setPort(0);/* w w  w  .ja  v a  2  s  .com*/
    String currentDir = new File(".").getCanonicalPath();
    String baseDir = currentDir + File.separator + "target";
    server.setBaseDir(baseDir);

    if (idp) {
        server.getHost().setAppBase("tomcat/idp/webapps");
    } else {
        server.getHost().setAppBase("tomcat/rp/webapps");
    }
    server.getHost().setAutoDeploy(true);
    server.getHost().setDeployOnStartup(true);

    Connector httpsConnector = new Connector();
    httpsConnector.setPort(Integer.parseInt(port));
    httpsConnector.setSecure(true);
    httpsConnector.setScheme("https");
    //httpsConnector.setAttribute("keyAlias", keyAlias);
    httpsConnector.setAttribute("keystorePass", "tompass");
    httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
    httpsConnector.setAttribute("truststorePass", "tompass");
    httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
    httpsConnector.setAttribute("clientAuth", "want");
    // httpsConnector.setAttribute("clientAuth", "false");
    httpsConnector.setAttribute("sslProtocol", "TLS");
    httpsConnector.setAttribute("SSLEnabled", true);

    server.getService().addConnector(httpsConnector);

    if (idp) {
        File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts");
        server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());

        File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp");
        server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
    } else {
        File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp");
        Context cxt = server.addWebapp("/fedizhelloworld", rpWebapp.getAbsolutePath());

        // Substitute the IDP port. Necessary if running the test in eclipse where port filtering doesn't seem
        // to work
        File f = new File(currentDir + "/src/test/resources/fediz_config_hok.xml");
        FileInputStream inputStream = new FileInputStream(f);
        String content = IOUtils.toString(inputStream, "UTF-8");
        inputStream.close();
        if (content.contains("idp.https.port")) {
            content = content.replaceAll("\\$\\{idp.https.port\\}", "" + idpHttpsPort);

            File f2 = new File(baseDir + "/test-classes/fediz_config_hok.xml");
            try (FileOutputStream outputStream = new FileOutputStream(f2)) {
                IOUtils.write(content, outputStream, "UTF-8");
            }
        }

        FederationAuthenticator fa = new FederationAuthenticator();
        fa.setConfigFile(currentDir + File.separator + "target" + File.separator + "test-classes"
                + File.separator + "fediz_config_hok.xml");
        cxt.getPipeline().addValve(fa);
    }

    server.start();

    return server;
}

From source file:Main.java

/**
 * File to Base64// w  ww. j  a  v  a 2 s.c  o m
 * @param filePath
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
public static String getBase64StringFromFile(String filePath) throws FileNotFoundException, IOException {
    byte[] buffer = null;
    File file = new File(filePath);
    FileInputStream fis = null;
    ByteArrayOutputStream bos = null;
    byte[] b = new byte[1000];
    try {
        fis = new FileInputStream(file);
        bos = new ByteArrayOutputStream(1000);
        int n;
        while ((n = fis.read(b)) != -1) {
            bos.write(b, 0, n);
        }
        fis.close();
        bos.close();
        buffer = bos.toByteArray();
    } catch (FileNotFoundException e) {
        throw e;
    } catch (IOException e) {
        throw e;
    } finally {
        if (bos != null) {
            try {
                bos.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }

    return Base64.encodeToString(buffer, Base64.DEFAULT);
}

From source file:Main.java

private static String readInStream(FileInputStream inStream) {
    try {//from  ww w .java  2 s.c o  m
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[512];
        int length = -1;
        while ((length = inStream.read(buffer)) != -1) {
            outStream.write(buffer, 0, length);
        }

        outStream.close();
        inStream.close();
        return outStream.toString();
    } catch (IOException e) {
        Log.i("FileTest", e.getMessage());
    }
    return null;
}