Example usage for java.io OutputStream close

List of usage examples for java.io OutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with this stream.

Usage

From source file:Main.java

public static void closeQuietly(OutputStream outputStream) {

    if (outputStream != null) {
        try {/*from w  w w. j a va  2s. c  o m*/
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            outputStream = null;
        }
    }
}

From source file:Main.java

public static void saveToFile(InputStream in, File dst) throws FileNotFoundException, IOException {
    OutputStream out = new FileOutputStream(dst);
    try {//from w  ww.j  a  v a 2 s  . c om
        transfer(in, out);
    } finally {
        out.close();
    }
}

From source file:Main.java

public static void close(OutputStream closeable) {
    if (closeable != null)
        try {//from  w w  w.j av  a  2  s  .  c om
            closeable.close();
        } catch (Exception ignored) {
        }
}

From source file:Main.java

/**
 * Creates a copy of the file/*  w w w.j a va2  s. c  o  m*/
 * @param in Source file
 * @param out Destination file
 * @throws IOException if the operation fails.
 * 
 */
public static void copyFile(File in, File out) throws IOException {
    InputStream in_stream = new FileInputStream(in);
    OutputStream out_stream = new FileOutputStream(out);
    copyStream(in_stream, out_stream);
    in_stream.close();
    out_stream.close();
}

From source file:Main.java

public static final void close(final OutputStream out) {
    if (out != null) {
        try {// ww  w  .ja v  a2 s  .co m
            out.close();
        } catch (IOException e) {
            // silent
        }
    }
}

From source file:Main.java

public final static void closeQuietly(OutputStream os) {
    try {/*from w  w w  . j  a v  a 2s  . c o m*/
        if (os != null)
            os.close();
    } catch (Exception e) {
        Log.e("OpenVPN", "closing OutputStream", e);
    }
}

From source file:Main.java

public static String getToken(String email, String password) throws IOException {
    // Create the post data
    // Requires a field with the email and the password
    StringBuilder builder = new StringBuilder();
    builder.append("Email=").append(email);
    builder.append("&Passwd=").append(password);
    builder.append("&accountType=GOOGLE");
    builder.append("&source=markson.visuals.sitapp");
    builder.append("&service=ac2dm");

    // Setup the Http Post
    byte[] data = builder.toString().getBytes();
    URL url = new URL("https://www.google.com/accounts/ClientLogin");
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setUseCaches(false);/*w  ww.  j av a2s .c o m*/
    con.setDoOutput(true);
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    con.setRequestProperty("Content-Length", Integer.toString(data.length));

    // Issue the HTTP POST request
    OutputStream output = con.getOutputStream();
    output.write(data);
    output.close();

    // Read the response
    BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String line = null;
    String auth_key = null;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("Auth=")) {
            auth_key = line.substring(5);
        }
    }

    // Finally get the authentication token
    // To something useful with it
    return auth_key;
}

From source file:Main.java

public static String copyAsset(Context context, String assetName, File dir) {
    try {//from  w  w w  .  ja v  a2s.c  o m
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File outFile = new File(dir, assetName);
        if (!outFile.exists()) {
            AssetManager assetManager = context.getAssets();
            InputStream in = assetManager.open(assetName);
            OutputStream out = new FileOutputStream(outFile);
            copyFile(in, out);
            in.close();
            out.close();
        }
        return outFile.getAbsolutePath();
    } catch (Exception e) {

    }
    return "";
}

From source file:Main.java

public static void write(InputStream in, OutputStream out) throws Throwable {
    int read = 0;
    while ((read = in.read()) != -1) {
        out.write(read);//w  w w .  j a  v a 2  s. co m
    }
    in.close();
    out.close();
    out.flush();
}

From source file:brut.androlib.mod.SmaliMod.java

public static boolean assembleSmaliFile(InputStream is, DexBuilder dexBuilder, boolean verboseErrors,
        boolean printTokens, File smaliFile) throws IOException, RecognitionException {

    // copy our filestream into a tmp file, so we don't overwrite
    File tmp = File.createTempFile("BRUT", ".bak");
    tmp.deleteOnExit();//  w w w.  j av a 2  s .  co m

    OutputStream os = new FileOutputStream(tmp);
    IOUtils.copy(is, os);
    os.close();

    return assembleSmaliFile(tmp, dexBuilder, verboseErrors, printTokens);
}