Example usage for java.io FileOutputStream flush

List of usage examples for java.io FileOutputStream flush

Introduction

In this page you can find the example usage for java.io FileOutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:com.att.aro.core.fileio.impl.FileManagerImpl.java

/**
 * flush and close the OutputStream// w  w  w.ja  v a 2  s  .com
 * 
 * @param outputStream
 * @throws IOException
 */
@Override
public void closeFile(FileOutputStream fileOutputStream) throws IOException {
    fileOutputStream.flush();
    fileOutputStream.close();
}

From source file:com.openshift.internal.client.ApplicationSSHSessionIntegrationTest.java

private void writeTo(InputStream inputStream, FileOutputStream fileOut) throws IOException {
    try {/*from  w ww.  ja va  2s.  c  o  m*/
        StreamUtils.writeTo(inputStream, fileOut);
    } finally {
        StreamUtils.close(inputStream);
        fileOut.flush();
        StreamUtils.close(fileOut);
    }
}

From source file:br.com.elotech.sits.service.AbstractService.java

public void writeReceived(File fileToWrite, Object received, Node node)
        throws XmlMappingException, IOException, ParserConfigurationException, SAXException {

    CastorMarshaller castorMarshallerByXSD = getCastorMarshallerByXSD(node);

    FileOutputStream fos = new FileOutputStream(fileToWrite);

    Result result = new StreamResult(fos);

    castorMarshallerByXSD.marshal(received, result);

    fos.flush();

    fos.close();/*from  w  w  w  . ja v a  2 s  .c  om*/

}

From source file:com.mengge.service.local.Scripts.java

public File getScriptFile() {
    InputStream inputStream = getClass().getResourceAsStream(RESOURCE_FOLDER + this.script);
    byte[] bytes;
    try {/*from  w w w  .j av  a2 s. c  o m*/
        bytes = IOUtils.toByteArray(inputStream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    String[] splittedName = this.script.split("\\.");
    File scriptFile;
    try {
        scriptFile = File.createTempFile(splittedName[0], "." + splittedName[1]);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    if (!scriptFile.exists()) {
        try {
            scriptFile.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    FileOutputStream output;
    try {
        output = new FileOutputStream(scriptFile, true);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }

    try {
        output.write(bytes);
        output.flush();
        output.close();
        return scriptFile;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:ambit.data.qmrf.QMRFAttachment.java

public void writeContent(File file) throws Exception {
    InputStream in = getContentAsStream();
    FileOutputStream out = new FileOutputStream(file);
    writeContent(in, out);/*from   w  w  w  .j a va 2  s.  c  o  m*/
    out.flush();
    out.close();
    in.close();
}

From source file:br.gov.jfrj.siga.ex.gsa.ExAdaptor.java

/**
 * Obtm a data da ltima execuo, caso o arquivo ou a data no
 * existam, salva a data informada por parmetro e a define como 
 * a data da ltima execuo.// w w w. ja v  a 2  s.  com
 * @param lastModified
 * @param path
 */
protected void getLastModified(Date lastModified, String path) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    File lastModifiedFile = new File(path);
    if (lastModifiedFile.exists()) {
        try (BufferedReader br = new BufferedReader(new FileReader(lastModifiedFile))) {
            String line;
            while ((line = br.readLine()) != null) {
                this.dateLastUpdated = dateFormat.parse(line);
                log.fine("A data da ltima  atualizao  " + line);
                break;
            }
        } catch (Exception e) {
            log.severe("Erro ao obter a data das ultimas alteraes!");
        }
    } else {
        String dateToSave = dateFormat.format(lastModified);
        try {
            FileOutputStream output = new FileOutputStream(lastModifiedFile);
            output.write(dateToSave.getBytes());
            output.flush();
            output.close();
        } catch (FileNotFoundException e) {
            log.severe("Erro salvando arquivo no disco!");
            log.info("verifique suas permisses e configuraes");
        } catch (IOException e) {
            log.severe("Erro ao escrever no arquivo!");
            log.severe("Erro: " + e.getMessage());
        }
        this.dateLastUpdated = lastModified;
        log.fine("A data da ltima  atualizao  " + dateToSave);
    }

}

From source file:com.phonegap.HttpHandler.java

private void writeToDisk(HttpEntity entity, String file) throws EOFException
/**//www.  j a va2 s  . c o  m
 * writes a HTTP entity to the specified filename and location on disk
 */
{
    int i = 0;
    String FilePath = "/sdcard/" + file;
    try {
        InputStream in = entity.getContent();
        byte buff[] = new byte[1024];
        FileOutputStream out = new FileOutputStream(FilePath);
        do {
            int numread = in.read(buff);
            if (numread <= 0)
                break;
            out.write(buff, 0, numread);
            i++;
        } while (true);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.torstenwalter.maven.plugins.SQLPlusMojo.java

private Map getEnvVars() throws MojoExecutionException {
    if (beforeSql != null) {
        Map envVars = new HashMap();
        try {//w w  w.ja  va  2 s . c o m
            envVars.putAll(CommandLineUtils.getSystemEnvVars());
        } catch (IOException e) {
            throw new MojoExecutionException("Could not copy system environment variables.", e);
        }
        envVars.put("SQLPATH", getPluginTempDirectory().getAbsolutePath());
        File login = new File(getPluginTempDirectory(), "login.sql");
        // login.deleteOnExit();
        try {
            login.createNewFile();
            FileOutputStream loginFos;
            loginFos = new FileOutputStream(login);
            loginFos.write(beforeSql.getBytes());

            loginFos.flush();
            loginFos.close();
        } catch (FileNotFoundException e) {
            throw new MojoExecutionException("Could not write " + login.getPath(), e);
        } catch (IOException e) {
            throw new MojoExecutionException("Could not write " + login.getPath(), e);
        }
        return envVars;
    } else {
        return null;
    }

}

From source file:fr.lip6.segmentations.ProcessHTML5.java

public void run() {
    //ArrayList<String> s1 = new ArrayList<String>();
    //ArrayList<String> s2= new ArrayList<String>();;
    String s1 = "";
    String s2 = "";
    try {//ww  w . j a v  a2 s.  c o  m
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection(
                "jdbc:mysql://" + Config.mysqlHost + "/" + Config.mysqlDatabase + "", Config.mysqlUser,
                Config.mysqlPassword);
        Statement st2 = con.createStatement();
        ResultSet rs = st2.executeQuery("select * from html5repo where descriptorbom<>''");
        while (rs.next()) {
            s1 = "";
            s2 = "";
            String d1 = rs.getString("descriptor");
            String d2 = rs.getString("descriptorbom");
            int dsize = d1.split(",").length;
            int d2size = d2.split(",").length;
            for (String s : d1.split(",")) {
                String[] part = s.split("=");
                if (!part[0].equals("PAGE")) {
                    if (part[1].equals("SECTION"))
                        s1 += "S";
                    if (part[1].equals("ARTICLE"))
                        s1 += "A";
                    if (part[1].equals("ASIDE"))
                        s1 += "D";
                    if (part[1].equals("HEADER"))
                        s1 += "H";
                    if (part[1].equals("FOOTER"))
                        s1 += "F";
                    if (part[1].equals("NAV"))
                        s1 += "N";
                }
            }

            for (String s : d2.split(",")) {
                String[] part = s.split("=");
                if (!part[0].equals("PAGE")) {
                    if (part[1].equals("SECTION"))
                        s2 += "S";
                    if (part[1].equals("ARTICLE"))
                        s2 += "A";
                    if (part[1].equals("ASIDE"))
                        s2 += "D";
                    if (part[1].equals("HEADER"))
                        s2 += "H";
                    if (part[1].equals("FOOTER"))
                        s2 += "F";
                    if (part[1].equals("NAV"))
                        s2 += "N";
                }
            }
            int ed = StringUtils.getLevenshteinDistance(s1.toString(), s2.toString());
            int edtotal = Math.max(s1.length(), s2.length());
            HashSet<Character> h1 = new HashSet<Character>(), h2 = new HashSet<Character>();
            for (int i = 0; i < s1.length(); i++) {
                h1.add(s1.charAt(i));
            }
            for (int i = 0; i < s2.length(); i++) {
                h2.add(s2.charAt(i));
            }
            h1.retainAll(h2);
            int inter = h1.size();

            char[] code1 = s1.toCharArray();
            char[] code2 = s2.toCharArray();

            Set set1 = new HashSet();

            for (char c : code1) {
                set1.add(c);
            }

            Set set2 = new HashSet();

            for (char c : code2) {
                set2.add(c);
            }

            int total = set1.size();

            System.out.println(set1);
            System.out.println(set2);
            System.out.println(s1);
            System.out.println(s2);
            System.out.println(rs.getString("id") + ". " + rs.getString("datafolder") + "=" + ed + "/" + edtotal
                    + "=" + ((double) ed / edtotal) + "," + inter + " of " + total + " Prec:("
                    + ((double) inter / total) + ")");
            Statement st3 = con.createStatement();
            //base=distancemax
            st3.execute("update html5repo set distance='" + ed + "',base='" + edtotal + "',found='" + inter
                    + "', expected='" + total + "' where datafolder='" + rs.getString("datafolder") + "'");
            File f = new File("/home/sanojaa/Documents/00_Tesis/work/dataset/dataset/data/"
                    + rs.getString("datafolder") + "/" + rs.getString("datafolder") + ".5.html");
            if (!f.exists()) {
                f.createNewFile();
            }
            FileOutputStream fop = new FileOutputStream(f);
            fop.write(rs.getString("src").getBytes());
            fop.flush();
            fop.close();

        }
    } catch (SQLException ex) {
        Logger.getLogger(SeleniumWrapper.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(HTML5Bom.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ProcessHTML5.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ProcessHTML5.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mockey.storage.xml.MockeyXmlFactory.java

public void writeStoreToXML(IMockeyStorage sourceStore, String destinationFileName) {

    try {//from  w w  w . j  a  v  a 2s .c o  m
        // WRITE STORE META FIRST
        File f = new File(destinationFileName);
        FileOutputStream fop = new FileOutputStream(f);

        String fileOutput = getStoreAsString(sourceStore, false);
        byte[] fileOutputAsBytes = fileOutput.getBytes(HTTP.UTF_8);
        fop.write(fileOutputAsBytes);
        fop.flush();
        fop.close();

        // WRITE EACH SERVICE
        for (Service service : sourceStore.getServices()) {
            File serviceFile = new File(MockeyXmlFileManager.getServiceFileNameOutputString(service));
            FileOutputStream serviceFOP = new FileOutputStream(serviceFile);
            MockeyXmlFileConfigurationGenerator xmlGeneratorSupport = new MockeyXmlFileConfigurationGenerator();
            Document serviceDoc = xmlGeneratorSupport.getServiceAsDocument(service);
            String serviceOutput = this.getDocumentAsString(serviceDoc);

            byte[] serviceOutputAsBytes = serviceOutput.getBytes(HTTP.UTF_8);
            serviceFOP.write(serviceOutputAsBytes);
            serviceFOP.flush();
            serviceFOP.close();
            logger.debug("Written to: " + serviceFile.getAbsolutePath());
        }

    } catch (Exception e) {
        logger.debug("Unable to write file", e);
    }
}