@Override public boolean hasNext() { try { next = reader.readLine(); if (next == null) { reader.close(); return false; } return true; }catch(IOException e) { throw X_Util.rethrow(e); } }
@Override public void onError(final Throwable e) { final Throwable unwrapped = X_Util.unwrap(e); if (unwrapped instanceof UnknownHostException) { failure[0] = true; } else if (unwrapped instanceof SocketException) { failure[0] = true; } else { e.printStackTrace(); X_Util.rethrow(e); } } });
@Override public Iterator<String> iterator() { try { // reader is closed by StringReader BufferedReader reader = new BufferedReader(new InputStreamReader(open())); return new StringReader(reader); } catch (IOException e) { throw X_Util.rethrow(e); } } };
@Override public Model loadPomString(String pomString) throws XmlPullParserException { try { return new MavenXpp3Reader().read(new StringReader(pomString)); } catch (IOException ignored) { throw X_Util.rethrow(ignored); } }
static ResourceCollection fromUrl(URL url, String pkg) { String path = url.toExternalForm(); File file; boolean jarUrl = path.startsWith("jar:"); if (jarUrl) path = path.substring("jar:".length()); boolean fileUrl = path.startsWith("file:"); if (fileUrl) path = path.substring("file:".length()); boolean jarFile = path.contains(".jar!"); if (jarFile) path = path.substring(0, path.indexOf(".jar!") + ".jar".length()); if (!(file = new java.io.File(path)).exists()) { path = path.replace("%20", " "); if (!(file = new java.io.File(path)).exists()) { //should be impossible since we get these urls from classloader throw X_Util.rethrow(new FileNotFoundException()); } } try { //TODO getOrMake; use an InitWithParamMap if (url.getProtocol().equals("jar")) { return new ResourceCollection(pkg, ((JarURLConnection)url.openConnection()).getJarFile()); } assert url.getProtocol().equals("file") : "ResourceCollection only handles url and file protocols"; if (jarFile) { return new ResourceCollection(pkg, new JarFile(file)); } return new ResourceCollection(file); }catch (IOException e) { throw X_Util.rethrow(e); } }
protected <X> X create(Class<? extends X> renderer) { try { return renderer.newInstance(); } catch (InstantiationException e) { throw X_Debug.rethrow(e.getCause() == null ? e : e.getCause()); } catch (IllegalAccessException e) { throw X_Util.rethrow(e); } }
protected <T> void callback(Future<T> future, ReceivesValue<T> receiver) { try { receiver.set(future.get()); return; } catch (InterruptedException e) { debug(e); Thread.interrupted(); } catch (ExecutionException e) { debug(e); throw X_Util.rethrow(X_Util.unwrap(e)); } }
public static synchronized File getXApiHome() { // We purposely don't cache this value so users can change it at runtime. String loc = X_Properties.getProperty(X_Namespace.PROPERTY_XAPI_HOME); try { if (loc == null) { // use a temporary directory instead File f = File.createTempFile("xapi", "home"); loc = f.getAbsolutePath(); X_Properties.setProperty(X_Namespace.PROPERTY_XAPI_HOME, loc); return f; } File home = new File(loc); if (!home.exists()) { X_Log.info("XApi home @ "+home.getCanonicalPath()+" does not exist."); if (home.mkdirs()) { X_Log.info("Successfully created home directory"); } else { X_Log.warn("Unable to create home directory; using temp file."); X_Properties.setProperty(X_Namespace.PROPERTY_XAPI_HOME, null); return getXApiHome(); } } return home; } catch (Throwable e) { throw X_Util.rethrow(e); } }