public static NestedIOException wrap(IOException e){ return new NestedIOException(e); }
public static void wrapAndThrow(String message,IOException e){ throw new NestedIOException(message,e); }
public static void wrapAndThrow(IOException e){ throw new NestedIOException(e); }
public static NestedIOException wrap(String message,IOException e){ return new NestedIOException(message,e); }
public static XmlReader createReader(File file) { try{ return createStaxReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8),file.getAbsolutePath()); }catch(IOException e){ throw new NestedIOException(e); } }
@Override public void run() { try { scan(result,rootResourceToScan,rootDirPath,subPattern); } catch (IOException e) { throw new NestedIOException(e); } } }));
public static XmlReader createReader(Resource resource) { try{ String resourceLocation = resource.toString(); return createStaxReader(new InputStreamReader(resource.getInputStream(), Charsets.UTF_8),resourceLocation); }catch(IOException e){ throw new NestedIOException(e); } }
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 Resource[] searchUrls(String... locationPatterns) { Args.notNull(locationPatterns,"location patterns"); Set<Resource> resources = new LinkedHashSet<Resource>(); for(String locationPattern : locationPatterns){ try { for(int i=0;i<values.length;i++){ Resource resource = values[i]; if(Resources.matcher.match(locationPattern,resource.getURL().toExternalForm())){ resources.add(resource); } } } catch (IOException e) { throw new NestedIOException(e); } } return resources.toArray(new Resource[resources.size()]); }
/** * scan all the resources match the given location pattern. * * @see ResourceScanner#scan(String) * * @throws NestedIOException if an {@link IOException} thrown by underlying scanner. */ public static ResourceSet scan(String locationPattern) throws NestedIOException { try { return new SimpleResourceSet(scanner.scan(locationPattern)); } catch (IOException e) { throw new NestedIOException(e); } }
@Override public void run() { try { final DefaultResourceScanner resourceScanner = new DefaultResourceScanner(loader); resourceScanner.setExecutorService(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); Collections2.addAll(result, resourceScanner.scan(locationPattern)); resourceScanner.getExecutorService().shutdownNow(); } catch (IOException e) { throw new NestedIOException(e); } } }));
public static Resource getResource(Resource current,String path) throws NestedIOException{ Args.notNull(current,"current resource"); Args.notNull(path,"resource path"); try { if(path.indexOf(':') > 0 || path.startsWith("/")){ return Resources.getResource(path); }else{ return current.createRelative(path); } } catch (IOException e) { throw new NestedIOException(e); } }
private static Properties readProperties(Resource resource) { InputStream is = null; try{ is = resource.getInputStream(); Properties properties = new Properties(); if(Strings.endsWithIgnoreCase(resource.getFilename(),".xml")){ properties.loadFromXML(is); }else{ properties.load(is); } return properties; }catch(IOException e){ throw new NestedIOException(e); }finally{ IO.close(is); } }
/** * Saving the given {@link Properties} to the given file use default charset {@link Charsets#defaultCharset()}. * * @throws NestedIOException if an I/O error occurs. */ public static void save(Properties props, File file) throws NestedIOException { Args.notNull(props,"properties"); Args.notNull(file,"file"); try{ if(!file.exists()){ file.createNewFile(); } if(Strings.endsWithIgnoreCase(file.getName(), ".xml")){ try(OutputStream out = new FileOutputStream(file)){ props.storeToXML(out, ""); } }else{ try(Writer writer = IO.createWriter(file)){ props.store(writer, ""); } } }catch(IOException e){ throw new NestedIOException("Error saving properties file '" + file.getAbsolutePath() + "', " + e.getMessage(), e); } }
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); } }
/** * Reads the given properties file. * * @throws NestedIOException if an I/O error occurs. */ public static ExProperties load(File file,Properties defaults) throws NestedIOException { Args.notNull(file,"file"); try { ExProperties props = null == defaults ? new ExProperties(file) : new ExProperties(file,defaults); if(Strings.endsWithIgnoreCase(file.getName(), ".xml")){ try(InputStream in = new FileInputStream(file)){ props.loadFromXML(in); } }else{ try(Reader reader = IO.createReader(file,Charset.defaultCharset())){ props.load(reader); } } return props; } catch (IOException e) { throw new NestedIOException("Error loading properties file '" + file.getAbsolutePath() + "', " + e.getMessage(), e); } }
protected GenericDbDriver[] loadDrivers() { String configFile = this.getClass().getSimpleName() + ".driver.json"; Resource r = Resources.getResource(this.getClass(),configFile); if(!r.exists()){ return EMPTY_DRIVES; } try { String keyPrefix = I18N.getLocalizedKeyPrefix(this) + ".drivers"; try(Reader reader = r.getInputStreamReader()){ GenericDbDriver[] drivers = JSON.decodeArray(reader, GenericDbDriver.class); for(GenericDbDriver driver : drivers){ I18N.localize(messageSource, driver, keyPrefix + "." + driver.getName()); } return drivers; } } catch (IOException e) { throw new NestedIOException("Error reading driver config file '" + r.getDescription() + "', " + e.getMessage(), e); } } }
throw new NestedIOException("Error loading .class file " + resource.getDescription() + "' : " + e.getMessage(), e); }catch (NoClassDefFoundError|ClassNotFoundException e){ log.info("Ignore loading class '{}', reason: {}", className, e.getMessage());
public static ExProperties load(Resource r) throws NestedIOException { try { if(r.isFile()){ return load(r.getFile()); }else{ ExProperties p = new ExProperties(); if(Strings.endsWithIgnoreCase(r.getFilename(), ".xml")){ try(InputStream in = r.getInputStream()){ p.loadFromXML(in); } }else{ try(Reader reader = r.getInputStreamReader()){ p.load(reader); } } return p; } } catch (IOException e) { throw new NestedIOException("Error loading properties from resource '" + r.getDescription() + "', " + e.getMessage(), e); } }