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:de.l3s.dlg.ncbikraken.ftp.NcbiFTPClient.java

public static void getMedline(MedlineFileType type) {
    FileOutputStream out = null;
    FTPClient ftp = new FTPClient();
    try {/*from  ww  w .  j  av a  2  s .  c o m*/
        // Connection String
        LOGGER.info("Connecting to FTP server " + SERVER_NAME);
        ftp.connect(SERVER_NAME);
        ftp.login("anonymous", "");
        ftp.cwd(BASELINE_PATH);
        ftp.cwd(type.getServerPath());

        try {
            ftp.pasv();
        } catch (IOException e) {
            LOGGER.error(
                    "Can not access the passive mode. Maybe a problem with your (Windows) firewall. Just try to run as administrator: \nnetsh advfirewall set global StatefulFTP disable");
            return;
        }

        for (FTPFile file : ftp.listFiles()) {
            if (file.isFile()) {
                File meshF = new File(file.getName());
                LOGGER.debug("Downloading file: " + SERVER_NAME + ":" + BASELINE_PATH + "/"
                        + type.getServerPath() + "/" + meshF.getName());
                out = new FileOutputStream(Configuration.INSTANCE.getMedlineDir() + File.separator + meshF);
                ftp.retrieveFile(meshF.getName(), out);
                out.flush();
                out.close();
            }
        }

    } catch (IOException ioe) {
        LOGGER.error(ioe.getMessage());

    } finally {
        IOUtils.closeQuietly(out);
        try {
            ftp.disconnect();
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }

}

From source file:br.com.bluesoft.pronto.controller.SprintController.java

@RequestMapping("/sprint/upload.action")
public String upload(final HttpServletRequest request, final int sprintKey) throws Exception {
    final Transaction tx = sessionFactory.getCurrentSession().beginTransaction();
    final Sprint sprint = (Sprint) sessionFactory.getCurrentSession().get(Sprint.class, sprintKey);

    final byte[] bytes = getImageBytes(request);

    final String folderPath = Config.getImagesFolder() + "/sprints/";
    final File folder = new File(folderPath);
    folder.mkdirs();// w ww  .j  a  v a 2 s  .c  o m

    final File file = new File(folderPath + sprint.getSprintKey());
    final FileOutputStream outputStream = new FileOutputStream(file);
    outputStream.write(bytes);
    outputStream.flush();

    sessionFactory.getCurrentSession().saveOrUpdate(sprint);
    sessionFactory.getCurrentSession().flush();

    tx.commit();
    return "redirect:editar.action?sprintKey=" + sprintKey;
}

From source file:com.nerve.commons.repository.tools.PropertiesLoader.java

/**
 * properties?/*w  w w  . ja v a  2  s . c om*/
 *
 * @param resourcesPath ?
 * @param key           ??
 * @param value         
 */
public void modifyProperties(String resourcesPath, String key, String value) {
    try {
        // ??
        properties.setProperty(key, value);
        FileOutputStream outputFile = new FileOutputStream(resourcesPath);
        properties.store(outputFile, "modify");
        outputFile.close();
        outputFile.flush();
    } catch (Exception e) {
    }
}

From source file:com.activiti.image.BpmnImageTest.java

protected void generateImage(BpmnModel bpmnModel, double scaleFactor) throws Exception {
    ProcessDiagramGenerator diagramGenerator = new DefaultProcessDiagramGenerator(scaleFactor);
    InputStream diagramStream = diagramGenerator.generatePngDiagram(bpmnModel, scaleFactor);
    FileOutputStream fileStream = new FileOutputStream("test.png");
    IOUtils.copy(diagramStream, fileStream);
    fileStream.flush();
    fileStream.close();//  ww  w  .  j a  va2s  . c  om
    assertNotNull(ImageIO.read(new File("test.png")));
}

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

public void execute() throws MojoExecutionException, MojoFailureException {
    if (!StringUtils.isEmpty(sqlCommand)) {
        // write statements to temporary file which can be passed to
        // sqlplus
        File tmpSqlFile;/*from   ww  w  .j a  v  a 2s  .  c  om*/
        try {
            tmpSqlFile = File.createTempFile("statements-", ".sql");
        } catch (IOException e) {
            throw new MojoExecutionException("Could not create file for sql statements", e);
        }
        tmpSqlFile.deleteOnExit();

        try {
            FileOutputStream fos = new FileOutputStream(tmpSqlFile);
            fos.write(sqlCommand.getBytes());
            fos.flush();
            fos.close();
        } catch (FileNotFoundException e) {
            throw new MojoExecutionException("Could not write sql statements to file", e);
        } catch (IOException e) {
            throw new MojoExecutionException("Could not write sql statements to file", e);
        }

        runScriptWithSqlPlus(tmpSqlFile, getEnvVars());
    } else if (sqlFile != null) {
        runScriptWithSqlPlus(sqlFile, getEnvVars());
    }
}

From source file:com.zokin.common.Application.java

public void Save_Append(String filename, String data) {
    try {/*from w w w . ja  v  a 2s.  c o  m*/
        /* . 
         * FileNotFoundExceptionContext 
         *   public abstract FileOutputStream openFileOutput(String name, int mode) 
         *   throws FileNotFoundException; 
         * openFileOutput(String name, int mode); 
         * // 
         *          /data/data//files/chenzheng_java.txt 
         *  
         *          MODE_PRIVATE   
         *          MODE_APPEND      
         *          MODE_WORLD_READABLE    
         *          MODE_WORLD_WRITEABLE   
         *  */
        FileOutputStream outputStream = openFileOutput(filename, Activity.MODE_APPEND);
        outputStream.write(data.getBytes());
        outputStream.flush();
        outputStream.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.zokin.common.Application.java

public void Save_Private(String filename, String data) {
    try {//  w  ww  . j av  a  2s.  co m
        /* . 
         * FileNotFoundExceptionContext 
         *   public abstract FileOutputStream openFileOutput(String name, int mode) 
         *   throws FileNotFoundException; 
         * openFileOutput(String name, int mode); 
         * // 
         *          /data/data//files/chenzheng_java.txt 
         *  
         *          MODE_PRIVATE   
         *          MODE_APPEND      
         *          MODE_WORLD_READABLE    
         *          MODE_WORLD_WRITEABLE   
         *  */
        FileOutputStream outputStream = openFileOutput(filename, Activity.MODE_PRIVATE);
        outputStream.write(data.getBytes());
        outputStream.flush();
        outputStream.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

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

/**
 * Salva data no arquivo informado/*  w w  w  .j a v  a 2  s. c  o m*/
 * @param lastModified
 * @param path
 */
protected void saveLastModified(Date lastModified, String path) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    File lastModifiedFile = new File(path);
    if (lastModifiedFile.exists()) {
        lastModifiedFile.delete();
    }
    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());
    }
}

From source file:edu.umd.cs.marmoset.utilities.UptimeDaemon.java

private void dumpToFile(String filename, String info) {
    FileOutputStream fos = null;
    try {/*from www .  ja v  a 2 s .c o  m*/
        fos = new FileOutputStream(filename);
        fos.write(info.getBytes());
        fos.flush();
    } catch (IOException ignore) {
        // ignore; we're trying to dump things on a best-effort basis so if things
        // don't get dumped, that's OK
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.jaspersoft.jasperserver.remote.services.async.ImportRunnable.java

protected File copyToTempFile(InputStream input) throws IOException {
    File tmp = File.createTempFile("import_", null);

    FileOutputStream fileStream = new FileOutputStream(tmp);

    byte[] buff = new byte[512];
    int read = input.read(buff);
    while (read > 0) {
        fileStream.write(buff, 0, read);
        read = input.read(buff);/*from   ww  w  .j a v a 2s. c  o  m*/
    }
    fileStream.flush();
    fileStream.close();

    return tmp;
}