private static void rm(String kill, boolean recursive) { File f = new File(kill); if (recursive) { HashSet<File> cycle = new HashSet<File>(); rmRecursive(f, cycle); } if (f.exists() && !f.delete()) { X_Log.warn(FileServiceImpl.class, "Unable to delete file ",f); } }
private static void rmRecursive(File f, HashSet<File> cycle) { if (cycle.add(f)) { if (f.isDirectory()) { for (File child : f.listFiles()) { rmRecursive(child, cycle); // Prevent symlink cycle recursion } if (!f.delete()) { X_Log.warn(FileServiceImpl.class,"Unable to delete",f); } } else if (f.isFile()) { if (!f.delete()) { X_Log.warn(FileServiceImpl.class,"Unable to delete",f); } } } }
public static void drain(final OutputStream out, final InputStream in) throws IOException { int size = 4096; byte[] buffer = new byte[size]; int read; while ((read = in.read(buffer)) >= 0) { if (read == 0) { try { Thread.sleep(0, 10000); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); X_Log.warn("Interrupted while draining input stream",in,"to output stream",out); return; } continue; } out.write(buffer, 0, read); if (size < 0x10000) { size <<= 0; } buffer = new byte[size]; } }
@Override public boolean saveFile(String path, String fileName, String contents, String charset) { File f = new File(path); if (!f.exists()) { if (!f.mkdirs()) { X_Log.warn("Unable to create parent directory", path,"in", f, new Throwable()); return false; } } f = new File(f, fileName); if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { X_Log.warn("Unable to create new file", fileName,"in", f, e); return false; } } try { X_IO.drain(new FileOutputStream(f), new ByteArrayInputStream(contents.getBytes())); } catch (IOException e) { X_Log.warn("Unable to save contents to file", f, e); return false; } return true; }
@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; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public RemovalHandler lock(SuccessHandler<AsyncLock> onLocked) { // TODO actually push the callback onto a deferred stack, // and return without blocking. try { lock.lock(); onLocked.onSuccess(this); } catch (Throwable e){ if (onLocked instanceof ErrorHandler) { try { ((ErrorHandler)onLocked).onError(e); } catch (Throwable ignored) {} } else { X_Log.warn("Error occured while performing lock callback on "+onLocked, onLocked); } } return RemovalHandler.DoNothing; }
annotatedPackages.add(((PackageElement)e).getQualifiedName().toString()); } else { X_Log.warn("Ignored an enclosing element that was not a TypeElement or package element" ,e,e.getClass());
@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; }
return unzip(resource, ((JarURLConnection)(url.openConnection())).getJarFile(), chmod); } else { X_Log.warn("Unknown get resource protocol "+url.getProtocol());
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); } }
final ConvertsValue<Object, Object> converter, final String prefix, final int depth) { if (depth > MAX_DEPTH) { X_Log.warn(getClass(), "Recursion sickness detected in "+cls+" from "+prefix+"; depth reached "+MAX_DEPTH); if (X_Log.loggable(LogLevel.TRACE)) { X_Log.trace("Consider using the @DoNotIndex annotation in the recursion chain produced by "+prefix);
final ConvertsValue<Object, Object> converter, String prefix, int depth) { if (depth > MAX_DEPTH) { X_Log.warn(getClass(), "Recursion sickness detected in "+cls+" from "+prefix+"; depth reached "+MAX_DEPTH); if (X_Log.loggable(LogLevel.TRACE)) { X_Log.trace("Consider using the @DoNotIndex annotation in the recursion chain produced by "+prefix);
callback.onError(e); if (X_Runtime.isDebug()) { X_Log.warn("IO Error", e);
callback.onError(e); if (X_Runtime.isDebug()) { X_Log.warn("IO Error", e);
writeMeta(injectionTargets, new File(target, instanceDir)); } catch (Throwable e) { X_Log.warn("Trouble encountered writing instance meta to ",new File(target, instanceDir),e);
@Override public IORequest<String> get(final String uri, final StringDictionary<String> headers, final IOCallback<IOMessage<String>> callback) { final String url = normalize(uri); if (callback.isCancelled()) { return cancelled; } try { final RequestBuilder request = newRequest(RequestBuilder.GET, url); normalizeHeaders(headers).forKeys(new ReceivesValue<String>() { @Override public void set(final String key) { final String value = headers.getValue(key); request.setHeader(key, value); } }); applySettings(request, IOConstants.METHOD_GET); final IORequestGwt req = createRequest(); sendRequest(request, req, callback, url, headers, IOConstants.METHOD_GET, null); return req; } catch (final Throwable e) { callback.onError(e); if (X_Runtime.isDebug()) { X_Log.warn("IO Error", e); } return cancelled; } }
callback.onError(e); if (X_Runtime.isDebug()) { X_Log.warn("IO Error", e);