Example usage for java.io InputStream close

List of usage examples for java.io InputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

public static ArrayList<String> getBookmark(String extractPath, String md5) {
    ArrayList<String> listBookMark = new ArrayList<>();
    StringBuilder reval = new StringBuilder();
    try {//  www . j a v a  2s. c o m
        InputStream in = new FileInputStream(extractPath + "/bookmark_" + md5);
        byte[] buf = new byte[1024];
        int c = 0;
        while ((c = in.read(buf)) >= 0) {
            reval.append(new String(buf, 0, c));
        }
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String[] arrSite = reval.toString().split(";");
    for (String str : arrSite) {
        if (str.length() > 0) {
            listBookMark.add(str);
        }
    }
    return listBookMark;
}

From source file:Main.java

private static String readStringFromStream(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader r = new BufferedReader(new InputStreamReader(in), 1000);
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        sb.append(line);/*from   www  .ja  v a 2 s. co  m*/
    }
    in.close();
    return sb.toString();
}

From source file:Main.java

public static String readFile(String path) throws IOException {
    InputStream is = new FileInputStream(new File(path));
    DataInputStream ds = new DataInputStream(is);
    // Estimated capacity, potential risk ???
    byte[] bytes = new byte[is.available()];
    ds.readFully(bytes);/* w  w w.  j  a  va 2s.  c  o m*/
    String text = new String(bytes);
    is.close();
    ds.close();
    return text;
}

From source file:com.awstrainers.devcourse.sdkdemos.S3Test.java

@BeforeClass
public static void createTestBucket() throws Exception {
    bucketName = "s3testbucket" + UUID.randomUUID();
    objectKey = "s3TestObject" + UUID.randomUUID();
    AmazonS3 client = new AmazonS3Client(cred);
    client.createBucket(bucketName);/*  www  .  j a v a2 s. co  m*/
    InputStream in = new StringInputStream("Hello!");
    client.putObject(bucketName, objectKey, in, new ObjectMetadata());
    in.close();
}

From source file:com.madgag.agit.GitTestUtils.java

public static File unpackRepoAndGetGitDir(String fileName) throws IOException, ArchiveException {
    File repoParentFolder = new File(FileUtils.getTempDirectory(),
            "unpacked-" + fileName + "-" + currentTimeMillis());
    InputStream rawZipFileInputStream = GitTestUtils.class.getResourceAsStream("/" + fileName);
    assertThat(rawZipFileInputStream, notNullValue());
    unzip(rawZipFileInputStream, repoParentFolder);
    rawZipFileInputStream.close();
    return repoParentFolder;
}

From source file:net.imatruck.betterweather.utils.JsonReader.java

public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
    InputStream is = new URL(url).openStream();
    try {/*from  w w w .  j  a v a 2  s  .co  m*/
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        String jsonText = readAll(rd);
        return new JSONObject(jsonText);
    } finally {
        is.close();
    }
}

From source file:com.ibm.jaggr.core.util.CopyUtil.java

public static void copy(Reader reader, OutputStream out) throws IOException {
    InputStream in = new ReaderInputStream(reader, "UTF-8"); //$NON-NLS-1$
    try {/*w w w  .ja  v a2s  .  c om*/
        IOUtils.copy(in, out);
    } finally {
        try {
            in.close();
        } catch (Exception ignore) {
        }
        try {
            out.close();
        } catch (Exception ignore) {
        }
    }
}

From source file:com.janoz.usenet.support.LogUtil.java

private static void copyStream(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[BUFF_SIZE];
    int len;//  w w w  .  j a va2s  . com

    while ((len = in.read(buffer)) >= 0) {
        out.write(buffer, 0, len);
    }
    in.close();
    out.close();
}

From source file:com.subakva.formicid.Main.java

private static void evaluateResource(Context cx, ScriptableObject scope, String resource) throws IOException {
    InputStream stream = Main.class.getResourceAsStream(resource);
    if (stream != null) {
        cx.evaluateReader(scope, new InputStreamReader(stream), resource, 1, null);
        stream.close();
    } else {// ww w  .j a va  2s.co m
        throw new RuntimeException("Unable to load resource: " + resource);
    }
}

From source file:controlador.Red.java

/**
 * Obtencion de un JTree mapeado pasandole una URL de un server FTP.
 * @param url URL formateada de la siguiente manera: protocolo://user:pwd@ip:puerto".
 * @return JTree formateado para hacer un set directamente.
 */// ww w  . j ava  2  s. co  m
public static JTree setArbolFTP(URL url) {
    try {
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();

        JTree tree = new Mapeador().mapearServer(is);

        is.close();
        return tree;
    } catch (IOException ex) {
        System.out.println("Problema al hacer set del ArbolFTP: " + ex.getLocalizedMessage());
    }

    return null;
}