public static String encode(String url, String charset) { if(null == url) { return url; } try { return URLEncoder.encode(url, charset); } catch (UnsupportedEncodingException e) { throw Exceptions.wrap(e); } }
public static String decode(String s) { if(null == s) { return s; } try { return URLDecoder.decode(s, Charsets.UTF_8_NAME); } catch (UnsupportedEncodingException e) { throw Exceptions.wrap(e); } }
public static String decode(String s, String charset) { if(null == s) { return s; } try { return URLDecoder.decode(s, charset); } catch (UnsupportedEncodingException e) { throw Exceptions.wrap(e); } }
@Override public File getFile() { try { return wrapped.getFile(); }catch (IOException e) { throw Exceptions.wrap(e); } }
public static String encode(String url) { if(null == url) { return url; } try { return URLEncoder.encode(url, Charsets.UTF_8_NAME); } catch (UnsupportedEncodingException e) { throw Exceptions.wrap(e); } }
@Override public InputStream getInputStream() throws NestedIOException { try { HttpEntity entity = httpResponse.getEntity(); return null == entity ? null : entity.getContent(); } catch (IOException e) { throw Exceptions.wrap("Error reading response body", e); } }
public static void writeString(OutputStream out,String string,Charset encoding) { byte[] data = string.getBytes(encoding); try { out.write(data); } catch (IOException e) { throw Exceptions.wrap(e); } }
@Override public File getFile() { try { return VfsUtils.getFile(this.resource); } catch (IOException e) { throw Exceptions.wrap(e); } }
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 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); } }
@Override public File getFile() { if (this.uri != null) { try { return super.getFile(this.uri); } catch (IOException e) { throw Exceptions.wrap(e); } } else { return super.getFile(); } }
public static XmlValidator of(Resource schemaResource) throws NestedIOException { try { return of(schemaResource.getInputStream()); } catch (IOException e) { throw Exceptions.wrap(e); } }
@Override public Boolean apply(DatabaseMetaData dm) { try { if(Strings.containsIgnoreCase(dm.getDatabaseProductName(), "mysql") && Strings.endsWith(dm.getDatabaseProductVersion(),"-MariaDB")) { return true; } if(Strings.containsIgnoreCase(dm.getDatabaseProductName(), "MariaDB")){ return true; } return false; } catch (SQLException e) { throw Exceptions.wrap(e); } } };
@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; }
/** * This implementation returns a File reference for the underlying class path * resource, provided that it refers to a file in the file system. * @see bingo.lang.io.Resources.util.ResourceUtils#getFile(java.net.URL, String) */ @Override public File getFile() throws NestedIOException { try { URL url = getURL(); if (url.getProtocol().startsWith(Urls.PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(url).getFile(); } return Files.fromUrl(url, getDescription()); } catch (IOException e) { throw Exceptions.wrap(e); } }
public static void write(Writer writer,List<Object[]> rows) throws NestedIOException { CSVPrinter printer = null; try{ printer = new CSVPrinter(writer, CSVFormat.DEFAULT); for(Object[] row : rows){ printer.printRecord(row); } }catch(IOException e){ throw Exceptions.wrap(e); }finally{ IO.close(writer); IO.close(printer); } }
public static ResourceSet scan(Resource rootDirResource,String subPattern) throws NestedIOException{ Args.notNull(rootDirResource,"rootDirResource"); Args.notEmpty(subPattern, "subPattern"); if(!rootDirResource.exists()) { return SimpleResourceSet.EMPTY; } try { return new SimpleResourceSet(scanner.scan(rootDirResource,subPattern)); } catch (IOException e) { throw Exceptions.wrap(e); } }
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); } }