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 int initTexture(Context context, int drawableId)// textureId
{
    int[] textures = new int[1];
    glGenTextures(1, textures, 0);//from   w  w  w .java  2s .c  o  m
    int textureId = textures[0];
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    InputStream is = context.getResources().openRawResource(drawableId);
    Bitmap bitmapTmp;
    try {
        bitmapTmp = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmapTmp, 0);
    bitmapTmp.recycle();

    return textureId;
}

From source file:com.mgatelabs.bytemapper.support.definitions.FormatDefinition.java

public static FormatDefinition load(InputStream is) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    FormatDefinition def;/*from w  w w .  j  av  a  2 s  .c o  m*/
    try {
        def = mapper.readValue(is, FormatDefinition.class);
    } finally {
        is.close();
    }
    def.sanity();
    return def;
}

From source file:com.netflix.edda.JsonHelper.java

public static <T> T decode(Class<T> c, InputStream input) throws IOException {
    try {/*from w w  w . j a v a 2  s .c o m*/
        TypeReference<T> ref = new TypeReference<T>() {
        };
        return createParser(input).readValueAs(ref);
    } finally {
        input.close();
    }
}

From source file:net.oneandone.shared.artifactory.App.java

private static void initLogging() {
    final InputStream resourceAsStream = App.class.getResourceAsStream("/logging.properties");
    try {//w w  w  .j  a  v  a  2  s  .co  m
        try {
            LogManager.getLogManager().readConfiguration(resourceAsStream);
        } finally {
            resourceAsStream.close();
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } catch (SecurityException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

public static String runCommand(String[] command, String workdirectory) {
    String result = "";
    Log.d("AppUtil.class", "#" + command);
    try {//ww  w  .  j a va  2 s .c  om
        ProcessBuilder builder = new ProcessBuilder(command);
        // set working directory
        if (workdirectory != null) {
            builder.directory(new File(workdirectory));
        }
        builder.redirectErrorStream(true);
        Process process = builder.start();
        InputStream in = process.getInputStream();
        byte[] buffer = new byte[1024];
        while (in.read(buffer) != -1) {
            String str = new String(buffer);
            result = result + str;
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static void createFileFormInputStream(InputStream is, String path) {
    try {// ww w.  ja  v a  2  s  .c om
        FileOutputStream fos = new FileOutputStream(path);
        byte[] buf = new byte[1376];
        while (is.read(buf) > 0) {
            fos.write(buf, 0, buf.length);
        }
        is.close();
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.eryansky.common.utils.encode.MD5Util.java

/**
 * ?MD5/*  w ww.  j  a  v  a 2  s  . com*/
 * @param file
 * @return
 * @throws IOException
 * @date   2012-1-9?3:15:43
 */
public static String getFileMD5String(File file) throws IOException {
    InputStream fis;
    fis = new FileInputStream(file);
    byte[] buffer = new byte[1024];
    int numRead = 0;
    while ((numRead = fis.read(buffer)) > 0) {
        messagedigest.update(buffer, 0, numRead);
    }
    fis.close();
    return bufferToHex(messagedigest.digest());
}

From source file:eurecom.constrained.devices.ReadZipFile.java

public static void unzip(final ZipFile zipfile, final File directory) throws IOException {

    final Enumeration<? extends ZipEntry> entries = zipfile.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        final File file = file(directory, entry);
        if (entry.isDirectory()) {
            continue;
        }/*from ww w. ja  v a  2s .  c o m*/
        final InputStream input = zipfile.getInputStream(entry);
        try {
            // copy bytes from input to file
        } finally {
            input.close();
        }
    }
}

From source file:Main.java

public static byte[] load(InputStream is) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len;//w w  w . j a v a  2  s . co  m
    while ((len = is.read(buffer)) != -1)
        baos.write(buffer, 0, len);
    baos.close();
    is.close();
    return baos.toByteArray();
}

From source file:net.ccghe.utils.Server.java

public static JSONObject Send(PostDataPairs pairs) {
    HttpClient client = new DefaultHttpClient();
    try {/*from  w ww. ja v  a2 s . co m*/
        HttpPost post = new HttpPost(serverURL);
        post.setEntity(new UrlEncodedFormEntity(pairs.get()));
        HttpResponse response = client.execute(post);

        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        String jsonResponse = convertStreamToString(stream);
        stream.close();
        if (entity != null) {
            entity.consumeContent();
        }
        JSONObject jObject = new JSONObject(jsonResponse);

        return jObject;
    } catch (ClientProtocolException e) {
        Log.e("EMOCHA", "ClientProtocolException ERR. " + e.getMessage());
    } catch (UnknownHostException e) {
        Log.e("EMOCHA", "UnknownHostException ERR. " + e.getMessage());
    } catch (IOException e) {
        Log.e("EMOCHA", "IOException ERR. " + e.getMessage());
    } catch (Exception e) {
        Log.e("EMOCHA", "Exception ERR. " + e.getMessage());
    }
    return null;
}