public static String toClasspath(URL cp) { try { String loc = cp.toURI().toString().replace("file:", ""); int ind = loc.indexOf("jar!"); if (ind == -1) { return loc; } return loc.substring(0, ind+3); } catch (Exception e) { throw X_Debug.rethrow(e); } } public static String[] toStrings(URL ... cp) {
public static InputStream toStreamUtf8(final String in) { try { return new ByteArrayInputStream(in.getBytes("utf-8")); } catch (final UnsupportedEncodingException e) { X_Debug.debug(e); return new ByteArrayInputStream(in.getBytes()); } }
@Override public File chmod(int chmod, File file) { assertValidChmod(chmod); Set<PosixFilePermission> perms = getPermissions(chmod); try { Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()), perms); } catch (IOException e) { X_Log.warn(getClass(), "Could not chmod file",file,"with permissions","0x"+Integer.toHexString(chmod), e); X_Debug.maybeRethrow(e); } return file; }
@Override public boolean hasNext() { try { next = reader.readLine(); if (next == null) { reader.close(); return false; } return true; }catch(IOException e) { throw X_Debug.wrap(e); } }
return false; }finally { if (X_Debug.isBenchmark()) { X_Log.info("Spent "+(now()-(max-timeout))+" millis flushing environment");
public ClassFile getClassData() { if (data == null) { try { DataInputStream in = new DataInputStream(open()); try { data = new ClassFile(in); }finally { in.close(); } } catch(IOException e) { throw X_Debug.wrap(e); } } return data; }
@Override public Object convert(final Object from) { final Object parent = converter.convert(from); try { return rootMethod.invoke(parent); } catch (final Exception e) { throw X_Debug.rethrow(e); } } };
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_Debug.wrap(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_Debug.wrap(e); } }
@Override public File createTempDir(String prefix, boolean deleteOnExit) { File f = null; try { f = File.createTempFile(prefix, ""); try { f.delete(); } catch (Exception e) { chmod(0x444, f); f.delete(); } f.mkdirs(); if (deleteOnExit) { GC.toKill.add(f.getCanonicalPath()); } chmod(0x777, f); } catch (IOException e) { X_Log.warn("Unable to create temporary directory for ", prefix, e); X_Debug.maybeRethrow(e); } return f; }
public String readAll() { StringBuilder b = new StringBuilder(); try { for (String line : readLines()) b.append(line).append('\n'); return b.toString(); } catch (IOException e) { throw X_Debug.rethrow(e); } }
if ((file = new java.io.File(path)).exists()) { throw X_Debug.wrap(new FileNotFoundException());
X_Debug.maybeRethrow(e);
public DigesterJre() { try { digest = MessageDigest.getInstance(getAlgorithm()); } catch (final NoSuchAlgorithmException e) { throw X_Debug.rethrow(e); } }
return Class.forName(cls); } catch (final ClassNotFoundException e) { throw X_Debug.rethrow(e);
@SuppressWarnings("unchecked") protected <T, U extends UserInterface<T>> U newUi(Class<? extends T> type, Class<? super U> uiType) { if (uiType == null) { throw new NullPointerException("Must specify UI type for "+type); } try { return (U) uiType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { X_Log.error(getClass(), "Unable to instantiate",uiType, e); throw X_Debug.rethrow(e); } }
public static Model loadPom(String fileLocation) { try { return service.loadPomFile(fileLocation); } catch (Exception e) { throw X_Debug.rethrow(e); } }
public static Model loadPomString(String pomString) { try { return service.loadPomString(pomString); } catch (Exception e) { throw X_Debug.rethrow(e); } }
@Override public Object convert(Object from) { Object parent = converter.convert(from); try { return rootMethod.invoke(parent); } catch (Exception e) { throw X_Debug.rethrow(e); } } };
@Override public UiRenderer renderInto(UserInterface ui, UiRenderingContext ctx, String path, Object value) { if (ui instanceof Appendable) { try { Appendable out = (Appendable)ui; if (ctx.isTemplateSet()) { String toString = ctx.applyTemplate(path, value); out.append(toString); } else { out.append(String.valueOf(value)); } } catch (IOException e) { throw X_Debug.rethrow(e); } } return this; }