Example usage for java.io BufferedOutputStream BufferedOutputStream

List of usage examples for java.io BufferedOutputStream BufferedOutputStream

Introduction

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

Prototype

public BufferedOutputStream(OutputStream out) 

Source Link

Document

Creates a new buffered output stream to write data to the specified underlying output stream.

Usage

From source file:com.mbrlabs.mundus.utils.TerrainIO.java

/**
 * Binary gziped format./*from   w w  w.ja  v  a 2 s  . co  m*/
 *
 * @param terrain
 */
public static void exportTerrain(ProjectContext projectContext, Terrain terrain) {
    float[] data = terrain.heightData;
    long start = System.currentTimeMillis();

    // create file
    File file = new File(FilenameUtils.concat(projectContext.path, terrain.terraPath));
    try {
        FileUtils.touch(file);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // write .terra
    try (DataOutputStream outputStream = new DataOutputStream(
            new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))))) {

        for (float f : data) {
            outputStream.writeFloat(f);
        }
        outputStream.flush();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    // write splatmap
    SplatMap splatmap = terrain.getTerrainTexture().getSplatmap();
    if (splatmap != null) {
        splatmap.savePNG(Gdx.files.absolute(FilenameUtils.concat(projectContext.path, splatmap.getPath())));
    }

    //Log.debug("Terrain export execution time (" + data.length + " floats): "
    //        + (System.currentTimeMillis() - start) + " ms");
}

From source file:de.tudarmstadt.ukp.dkpro.core.frequency.tfidf.util.TfidfUtils.java

public static void serialize(Object object, String fileName) throws Exception {
    File file = new File(fileName);
    if (!file.exists())
        FileUtils.touch(file);//from   ww  w .jav a  2 s .  c o m
    if (file.isDirectory()) {
        throw new IOException("A directory with that name exists!");
    }
    ObjectOutputStream objOut;
    objOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    objOut.writeObject(object);
    objOut.flush();
    objOut.close();

}

From source file:app.common.X3DViewer.java

/**
 * View an X3D file using an external X3DOM player
 *
 * @param grid/*  w ww  .j a  va 2  s  . c om*/
 * @param smoothSteps
 * @param maxDecimateError
 * @throws IOException
 */
public static void viewX3DOM(Grid grid, int smoothSteps, double maxDecimateError) throws IOException {
    // TODO: Make thread safe using tempDir
    String dest = "/tmp/ringpopper/";
    File dir = new File(dest);
    dir.mkdirs();

    String pf = "x3dom/x3dom.css";
    String dest_pf = dest + pf;
    File dest_file = new File(dest_pf);
    File src_file = new File("src/html/" + pf);
    if (!dest_file.exists()) {
        System.out.println("Copying file: " + src_file + " to dir: " + dest);
        FileUtils.copyFile(src_file, dest_file, true);
    }

    pf = "x3dom/x3dom.js";
    dest_pf = dest + pf;
    dest_file = new File(dest_pf);
    src_file = new File("src/html/" + pf);
    if (!dest_file.exists()) {
        System.out.println("Copying file: " + src_file + " to dir: " + dest);
        FileUtils.copyFile(src_file, dest_file, true);
    }
    File f = new File("/tmp/ringpopper/out.xhtml");
    FileOutputStream fos = new FileOutputStream(f);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    PrintStream ps = new PrintStream(bos);

    try {
        ps.println(
                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
        ps.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        ps.println("<head>");
        ps.println("<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />");
        ps.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
        ps.println("<title>Ring Popper Demo</title>");
        //            ps.println("<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>");
        ps.println("<link rel='stylesheet' type='text/css' href='x3dom/x3dom.css'></link>");
        ps.println("</head>");
        ps.println("<body>");

        ps.println("<p class='case'>");
        GridSaver.writeIsosurfaceMaker(grid, bos, "x3d", smoothSteps, maxDecimateError);

        //            ps.println("<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>");
        ps.println("<script type='text/javascript' src='x3dom/x3dom.js'></script>");

        ps.println("</p>");
        ps.println("</body></html>");
    } finally {
        bos.flush();
        bos.close();
        fos.close();
    }

    Desktop.getDesktop().browse(f.toURI());
}

From source file:cs.register.cddao.java

@Override
public void salvaresair(int status) {
    ObjectOutputStream objectOut = null;
    try {//from www.  j a  va2 s. c  o  m
        objectOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("save")));
        objectOut.writeObject(this.list1);

        objectOut.close();
    } catch (IOException ex) {
        Logger.getLogger(cddao.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            objectOut.close();
        } catch (IOException ex) {
            Logger.getLogger(cddao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (status == 0)
        System.exit(0);
}

From source file:com.twinsoft.convertigo.engine.util.ZipUtils.java

public static void makeZip(String archiveFileName, String sDir, String sRelativeDir, List<File> excludedFiles)
        throws Exception {
    FileOutputStream fos = new FileOutputStream(archiveFileName);
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos));
    int nbZipEntries = ZipUtils.putEntries(zos, sDir, sRelativeDir, excludedFiles);
    if (nbZipEntries > 0)
        zos.close();//from   w  ww  .  ja va 2  s.  c o  m
}

From source file:com.code.savemarks.utils.Utils.java

/**
 * Serialize an object into a byte array.
 * //ww w . jav a 2s.  c  om
 * @param obj An object to be serialized.
 * @return A byte array containing the serialized object
 * @throws QueueFailureException If an I/O error occurs during the
 * serialization process.
 */
public static byte[] serialize(Object obj) {
    try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream(bytesOut));
        objectOut.writeObject(obj);
        objectOut.close();
        return encodeBase64(bytesOut.toByteArray());
    } catch (IOException e) {
        throw new QueueFailureException(e);
    }
}

From source file:cs.register.abrirefeichar.java

@Override
public void salvaresair(int status) {
    ObjectOutputStream objectOut = null;
    try {//  w w  w  .  j  av a  2  s.  c  om
        objectOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("save")));
        objectOut.writeObject(this.list1);

        objectOut.close();
    } catch (IOException ex) {
        Logger.getLogger(abrirefeichar.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            objectOut.close();
        } catch (IOException ex) {
            Logger.getLogger(abrirefeichar.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (status == 0)
        System.exit(0);
}

From source file:com.cyberway.issue.util.SurtPrefixSet.java

/**
 * Allow class to be used as a command-line tool for converting 
 * URL lists (or naked host or host/path fragments implied
 * to be HTTP URLs) to implied SURT prefix form. 
 * /*from w  ww.  j a va2  s  .  co  m*/
 * Read from stdin or first file argument. Writes to stdout. 
 *
 * @param args cmd-line arguments: may include input file
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    InputStream in = args.length > 0 ? new BufferedInputStream(new FileInputStream(args[0])) : System.in;
    PrintStream out = args.length > 1 ? new PrintStream(new BufferedOutputStream(new FileOutputStream(args[1])))
            : System.out;
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String line;
    while ((line = br.readLine()) != null) {
        if (line.indexOf("#") > 0)
            line = line.substring(0, line.indexOf("#"));
        line = line.trim();
        if (line.length() == 0)
            continue;
        out.println(prefixFromPlain(line));
    }
    br.close();
    out.close();
}

From source file:Main.java

public static boolean bufferedCopyStream(InputStream inStream, OutputStream outStream, boolean closeStream)
        throws Exception {
    BufferedInputStream bis = new BufferedInputStream(inStream);
    BufferedOutputStream bos = new BufferedOutputStream(outStream);
    while (true) {
        int data = bis.read();
        if (data == -1) {
            break;
        }//from  ww  w .j  a  va2 s  .  co  m
        bos.write(data);
    }
    bos.flush();
    if (closeStream) {
        bos.close();
    }
    return true;
}

From source file:aiai.apps.commons.utils.ZipUtils.java

/**
 * Creates a zip file at the specified path with the contents of the specified directory.
 * NB://w w w  . ja v a  2 s .  c  om
 *
 * @param directory The path of the directory where the archive will be created. eg. c:/temp
 * @param zipFile zip file
 * @throws IOException If anything goes wrong
 */
public static void createZip(File directory, File zipFile) throws IOException {

    try (FileOutputStream fOut = new FileOutputStream(zipFile);
            BufferedOutputStream bOut = new BufferedOutputStream(fOut);
            ZipArchiveOutputStream tOut = new ZipArchiveOutputStream(bOut)) {
        addFileToZip(tOut, directory, "");
    }
}