List of usage examples for java.io Reader close
public abstract void close() throws IOException;
From source file:com.ibm.jaggr.core.util.CopyUtil.java
public static void copy(String str, OutputStream out) throws IOException { Reader reader = new StringReader(str); try {/*from w w w .j av a 2 s .c om*/ IOUtils.copy(reader, out); } finally { try { reader.close(); } catch (Exception ignore) { } try { out.close(); } catch (Exception ignore) { } } }
From source file:com.ibm.jaggr.core.util.CopyUtil.java
public static void copy(String str, Writer writer) throws IOException { Reader reader = new StringReader(str); try {/*w ww. j a v a 2 s. co m*/ IOUtils.copy(reader, writer); } finally { try { reader.close(); } catch (Exception ignore) { } try { writer.close(); } catch (Exception ignore) { } } }
From source file:com.netflix.edda.JsonHelper.java
public static <T> T decode(Class<T> c, Reader input) throws IOException { try {//from w ww .ja va 2 s. c o m TypeReference<T> ref = new TypeReference<T>() { }; return createParser(input).readValueAs(ref); } finally { input.close(); } }
From source file:com.google.mr4c.sources.FilesDatasetSourceConfig.java
private static FilesDatasetSourceConfig loadFromContent(ConfigDescriptor descriptor) throws IOException { Reader reader = descriptor.getContent(); try {//from w w w . jav a2s . co m return load(reader); } finally { reader.close(); } }
From source file:de.huxhorn.sulky.io.IOUtilities.java
/** * Unconditionally close an <code>Reader</code>. * <p>//from w w w. j a v a2 s. c o m * Equivalent to {@link Reader#close()}, except any exceptions will be ignored. * {@link InterruptedIOException} is handled correctly by {@link #interruptIfNecessary(Throwable)}. * This is typically used in finally blocks. * * @param x the Reader to close, may be null or already closed */ public static void closeQuietly(Reader x) { if (x == null) { return; } try { x.close(); } catch (IOException e) { interruptIfNecessary(e); } }
From source file:com.ibm.jaggr.core.util.CopyUtil.java
public static int copy(Reader reader, Writer writer) throws IOException { try {// ww w . j a va 2 s .co m return IOUtils.copy(reader, writer); } finally { try { reader.close(); } catch (Exception ignore) { } try { writer.close(); } catch (Exception ignore) { } } }
From source file:com.ibm.jaggr.core.util.CopyUtil.java
public static void copy(InputStream in, Writer writer) throws IOException { Reader reader = new InputStreamReader(in, "UTF-8"); //$NON-NLS-1$ try {// w w w. j a va 2s . com IOUtils.copy(reader, writer); } finally { try { reader.close(); } catch (Exception ignore) { } try { writer.close(); } catch (Exception ignore) { } } }
From source file:org.apiwatch.util.IO.java
public static APIScope getAPIData(String source, String format, String encoding, String username, String password) throws IOException, SerializationError, HttpException { File file = new File(source); APIScope scope = null;/*from w w w . ja va2 s .co m*/ if (file.isFile()) { if (format == null) { /* get format from file extension */ format = source.substring(source.lastIndexOf('.') + 1); } InputStream in = new FileInputStream(file); Reader reader = new InputStreamReader(in, encoding); scope = Serializers.loadAPIScope(reader, format); reader.close(); in.close(); } else { /* maybe source is a URL */ DefaultHttpClient client = new DefaultHttpClient(); if (username != null && password != null) { client.getCredentialsProvider().setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(username, password)); } HttpResponse response = client.execute(new HttpGet(source)); if (response.getStatusLine().getStatusCode() >= 400) { throw new HttpException(response.getStatusLine().getReasonPhrase()); } HttpEntity entity = response.getEntity(); ContentType contentType = ContentType.fromHeader(entity.getContentType().getValue()); if (entity.getContentEncoding() != null) { encoding = entity.getContentEncoding().getValue(); } else if (contentType.charset != null) { encoding = contentType.charset; } if (format == null) { format = contentType.type; } InputStream in = entity.getContent(); Reader reader = new InputStreamReader(in, encoding); scope = Serializers.loadAPIScope(reader, format); reader.close(); in.close(); client.getConnectionManager().shutdown(); } return scope; }
From source file:com.microsoft.tfs.util.IOUtils.java
/** * Unconditionally closes the specified {@link Reader}, safely handling any * {@link IOException} thrown by the {@link Reader#close()} method. If the * log for this class is properly configured, any such exception will be * logged, but it will never cause an exception to be thrown to the caller. * This method is typically called from a finally block in caller code. * * @param reader/*ww w.ja v a2 s . c o m*/ * the {@link Reader} to close (must not be <code>null</code>) */ public static void closeSafely(final Reader reader) { Check.notNull(reader, "reader"); //$NON-NLS-1$ try { reader.close(); } catch (final IOException e) { if (log.isTraceEnabled()) { log.trace("error closing Reader", e); //$NON-NLS-1$ } } }
From source file:com.asksven.commandcenter.valueobjects.CommandReaderWriter.java
public static CommandCollection readStream(InputStream source) throws Exception { CommandCollection data = null;//w ww. ja v a 2 s. c o m if (source == null) { return null; } Gson gson = new Gson(); Reader reader = new InputStreamReader(source); // Now do the magic. data = gson.fromJson(reader, CommandCollection.class); reader.close(); return data; }