@Override public void free() throws SQLException { string = null; IO.close(reader); }
@Override public void free() throws SQLException { bytes = null; IO.close(stream); }
@Override public void close() throws IOException { IO.close(out); try { writer.close(); } catch (XMLStreamException e) { throw wrap(e); } }
public static byte[] readByteArrayAndClose(InputStream is) { try{ return readByteArray(is); }finally{ close(is); } }
public static byte[] readByteArrayAndClose(Reader reader) { try{ return readByteArray(reader); }finally{ close(reader); } }
public static String readStringAndClose(InputStream is, Charset charset) { try{ return readString(is, charset); }finally{ close(is); } }
public static String readStringAndClose(Reader reader) { try{ return readString(reader); }finally{ close(reader); } }
public static String getResourceAsString(Class<?> loaderClass,String resource,Charset charset){ InputStream is = null; try{ is = loaderClass.getResourceAsStream(resource); if(null == is){ return null; } return IO.readString(is,charset); }finally{ IO.close(is); } }
public static byte[] readByteArray(Reader reader) { ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(out); try{ copy(reader,writer); writer.flush(); return out.toByteArray(); }catch(IOException e){ throw Exceptions.wrap(e); }finally{ close(writer); } }
public static XmlDocument load(File file) { InputStreamReader reader = null; try{ reader = new InputStreamReader(new FileInputStream(file),Charsets.UTF_8); Document doc = parseDocument(reader); return new DomDocument(doc,file.getAbsolutePath()); }catch(IOException e){ throw new NestedIOException(e.getMessage(),e); }finally{ IO.close(reader); } }
@Override public void close() throws IOException { IO.close(in); try { real.close(); } catch (XMLStreamException e) { throw new XmlException(e.getMessage(),e); } }
public static byte[] readByteArray(File file) { FileInputStream in = null; try{ in = new FileInputStream(file); return readByteArray(in); }catch(IOException e){ throw Exceptions.wrap(e); }finally{ close(in); } }
public static void writeString(File file,String string, Charset encoding){ FileOutputStream out = null; try{ out = new FileOutputStream(file); writeString(out,string,encoding); }catch(IOException e){ throw Exceptions.wrap(e); }finally{ close(out); } }
/** * Get the contents of an {@link File} as a String using the specified character encoding. */ public static String readString(File file,Charset encoding) throws NestedIOException { FileInputStream fis = null; try{ fis = new FileInputStream(file); return readString(fis, encoding); }catch(IOException e){ throw Exceptions.wrap(e); }finally{ close(fis); } }
protected static List<String[]> readList(Reader reader,CSVFormat format) throws NestedIOException { Args.notNull(reader,"reader"); CSVParser parser = null; try{ parser = new CSVParser(reader, format); return parser.getRecords1(); }catch(IOException e){ throw Exceptions.wrap(e); }finally{ IO.close(reader); IO.close(parser); } }
@Override public String getContent() throws NestedIOException { InputStreamReader r = null; try { r = getInputStreamReader(); return IO.readString(r); }finally{ IO.close(r); } }
@Override public InputStreamReader getInputStreamReader(Charset charset) { InputStreamReader reader = null; try{ reader = new InputStreamReader(getInputStream(),Charsets.get(charset)); }catch(IOException e){ IO.close(reader); throw Exceptions.wrap(e); } return reader; }
public static XmlDocument load(Resource resource) throws NestedIOException { InputStreamReader reader = null; try{ reader = resource.getInputStreamReader(); Document doc = parseDocument(reader); return new DomDocument(doc,null == resource.getURL() ? null : resource.getURL().toString()); }catch(IOException e){ throw new NestedIOException(e.getMessage(),e); }finally{ IO.close(reader); } }
protected void readDefinitions(BeanContainer container, Resource resource, boolean defaultOverride) { if (!Strings.endsWithIgnoreCase(resource.getFilename(), ".xml")) { return; } XmlReader reader = null; try { reader = XML.createReader(resource); if (reader.nextToStartElement(BEANS_ELEMENT)) { readBeans(container, resource, reader, new LoaderContext(defaultOverride)); } } finally { IO.close(reader); } }