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.camel.trainreserve.TicketReserver.java

private static void getCaptchaImg() {
    String url = "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&0.20558934959469144";
    ByteArrayOutputStream outStream = JDKHttpsClient.doGetImg(url, cookieStr);
    if (outStream.size() > 0) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        File imageFile = new File("G://12306OCR-2//" + (new Date()).getTime() + ".png");
        try {/*www.j  av a 2s.c  om*/
            FileOutputStream fos = new FileOutputStream(imageFile);
            byte[] bytes = outStream.toByteArray();
            fos.write(bytes);
            fos.flush();
            fos.close();
            outStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println(Thread.currentThread().getName() + " return empty");
    }
}

From source file:Main.java

public static void imgCacheWrite(Context context, String cacheImgFileName, String imgBase64Str) {
    File cacheImgFile = new File(context.getFilesDir() + "/" + cacheImgFileName);
    if (cacheImgFile.exists()) {
        cacheImgFile.delete();//from  ww w .j a v a  2s.c  o  m
    }

    FileOutputStream fos;
    try {
        fos = context.openFileOutput(cacheImgFileName, Context.MODE_PRIVATE);
        fos.write(imgBase64Str.getBytes("utf-8"));
        fos.flush();
        fos.close();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.aqnote.shared.cryptology.cert.util.X509CertFileUtil.java

public static void writeCert(String b64cert, String certFileName) throws IOException {

    if (StringUtils.isBlank(b64cert) || StringUtils.isBlank(certFileName)) {
        return;/*from   ww w. j ava  2 s  .  c  o  m*/
    }
    FileOutputStream fos1 = new FileOutputStream(certFileName);
    fos1.write(b64cert.getBytes());
    fos1.flush();
    fos1.close();
}

From source file:Main.java

private static void blockingStoreBitmap(Context context, Bitmap bitmap, String filename) {
    FileOutputStream fOut = null;
    try {//from  ww w .  j  a  v  a2s .  co m
        fOut = context.openFileOutput(filename, Context.MODE_PRIVATE);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (fOut != null) {
                fOut.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static boolean writeFile(String to, String value) {
    boolean result = false;

    FileOutputStream out = null;

    try {/*w w  w .  jav a 2s.  c o m*/
        out = new FileOutputStream(to);
        byte[] buffer = value.getBytes();
        out.write(buffer, 0, value.length());
        out.flush();
        result = true;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
        }
    }
    return result;

}

From source file:gov.nasa.ensemble.dictionary.nddl.ModelGenerator.java

protected static FileOutputStream[] makeModelOutputStreams() throws IOException {
    FileOutputStream streams[] = { new FileOutputStream(TMP_PATH.append(OBJECTS_NDDL).toFile()),
            new FileOutputStream(TMP_PATH.append(MODEL_NDDL).toFile()),
            new FileOutputStream(TMP_PATH.append(INITIAL_STATE_NDDL).toFile()) };

    for (FileOutputStream stream : streams)
        stream.flush();

    return streams;
}

From source file:be.vds.jtbdive.core.utils.FileUtilities.java

public static void replaceAllInFile(File file, String oldValue, String newValue) throws IOException {
    byte[] b = new byte[(int) file.length()];
    FileInputStream is = new FileInputStream(file);
    is.read(b);//from www  .  j a  va  2  s  . c om
    is.close();
    String s = new String(b);
    s = s.replaceAll(oldValue, newValue);
    FileOutputStream os = new FileOutputStream(file);
    os.write(s.getBytes());
    os.flush();
    os.close();
}

From source file:Main.java

public static boolean storeImage(Context context, Bitmap bmp, boolean isRotate) {

    // use the current data&time for image file name
    String takenTime_YYMMDD_HHMMSS = new SimpleDateFormat(DATA_FORMAT).format(new Date());

    // saved bitmap: full path
    String path = PIC_ROOT_PATH + takenTime_YYMMDD_HHMMSS;
    File f = new File(path);

    if (f != null && !f.getParentFile().exists()) {
        f.getParentFile().mkdirs();/*from w  ww  . j  a  v  a  2s  .  c  o  m*/
    }

    if (isRotate) {
        Matrix matrix = new Matrix();
        matrix.reset();
        matrix.postRotate(90);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    }

    try {
        FileOutputStream out = new FileOutputStream(f);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    return updateGallery(context, bmp, takenTime_YYMMDD_HHMMSS);
}

From source file:Main.java

public static boolean writeToExternalStoragePublic(String filename, String fileContent) {
    boolean saved = false;
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
    if (isExternalStorageAvailable() && !isExternalStorageReadOnly()) {
        try {//from  w ww  .  j a  v  a  2  s .  c  om
            boolean exists = (new File(path)).exists();
            if (!exists) {
                new File(path).mkdirs();
            }

            //Remote legacy file
            File file = new File(path + filename);
            file.delete();

            // Open output stream
            FileOutputStream fOut = new FileOutputStream(path + filename, true);
            fOut.write(fileContent.getBytes());
            // Close output stream
            fOut.flush();
            fOut.close();

            saved = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return saved;
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.log.ProblemsDatabaseUpdateJobTest.java

private static void createEmptyZip(File file) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(MINIMAL_ZIP_FILE, 0, 22);/*from  w w w .  java 2 s  .  co  m*/
    fos.flush();
    fos.close();
}