@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); } }
@Override public Model setProperty(final String key, final Object value) { try { map.put(key, value); } catch (final Throwable e) { X_Log.error(e); } return this; }
@Override public String getFileMaybeUnzip(String file, int chmod) { File f = new File(file); if (f.getAbsolutePath().contains("jar!")) { try { return unzip(file, new JarFile(f), chmod); } catch (IOException e) { X_Log.error(getClass(), "Unable to unzip", f, "from file", file,"with chmod",Integer.toHexString(chmod), e); } } return getPath(file); }
@Override public String unzip(String resource, JarFile jarFile, int chmod) { final ZipEntry entry = jarFile.getEntry(resource); String fileName = null; final File file; try { // Don't close this jar; it's in use by the classloader InputStream is = jarFile.getInputStream(entry); file = File.createTempFile(resource.replace('/', '_'), ""); fileName = file.getCanonicalPath(); try (FileOutputStream fOut = new FileOutputStream(file)) { X_IO.drain(fOut, is); } chmod(chmod, file); file.deleteOnExit(); return fileName; } catch (Throwable e) { X_Log.error("Error encountered unzipping jar entry",resource,"from",jarFile," Entry:", entry, e); } return fileName; }
/** * @param propertyType * @param src * @param primitives * @param ctx * @return */ @SuppressWarnings("unchecked") protected Object readEnum(final Class propertyType, final CharIterator src, final PrimitiveSerializer primitives, final ModelDeserializationContext ctx) { try { final int ordinal = primitives.deserializeInt(src); if (ordinal == -1) { return null; } final Method method = propertyType.getMethod("values"); final Object values = method.invoke(null); return Array.get(values, ordinal); } catch (final Throwable e) { X_Log.error(getClass(), "Error reading enum "+propertyType+" from "+src); throw X_Debug.rethrow(e); } }
X_Log.error("Error trying to load / unzip resouce "+resource+" using file "+url, e); X_Debug.maybeRethrow(e);
@Override public void run() { try { if (file.exists()) { file.delete(); } final FileOutputStream result = new FileOutputStream(file); X_IO.drain(result, X_IO.toStreamUtf8(serialized.toString())); callback.onSuccess(model); X_Log.info(getClass(), "Saved model to ",file); } catch (final IOException e) { X_Log.error(getClass(), "Unable to save model "+model, e); if (callback instanceof ErrorHandler) { ((ErrorHandler) callback).onError(e); } } } });
@Override public void run() { final RemovalHandler handler = scope.get(); String result; try { result = X_IO.toStringUtf8(new FileInputStream(file)); final M model = deserialize(modelClass, new StringCharIterator(result)); callback.onSuccess(model); } catch (final Exception e) { X_Log.error(getClass(), "Unable to load file for model "+modelKey); if (callback instanceof ErrorHandler) { ((ErrorHandler) callback).onError(new ModelNotFoundException(modelKey)); } } finally { handler.remove(); } } });
f = getFilesystemRoot(); } catch (final IOException e) { X_Log.error(getClass(), "Unable to load filesystem root", e); if (callback instanceof ErrorHandler) { ((ErrorHandler) callback).onError(e);
f = getFilesystemRoot(); } catch (final IOException e) { X_Log.error(getClass(), "Unable to load filesystem root", e); if (callback instanceof ErrorHandler) { ((ErrorHandler) callback).onError(e); f = generateFile(f); } catch (final IOException e) { X_Log.error(getClass(), "Unable to save model "+model, e); if (callback instanceof ErrorHandler) { ((ErrorHandler) callback).onError(e);
((ErrorHandler)successHandler).onError(e); X_Log.error(getClass(), "Error draining input stream", info, in, e); } finally { X_Log.debug(getClass(), "Finished blocking", this);
callback.onError(e); if (X_Runtime.isDebug()) { X_Log.error(getClass(), "Error sending request",url,e);
} catch (final Throwable t) { t.printStackTrace(); X_Log.error("Error invoking IO callback on",callback,"for request",url, t);
X_Log.error("Error invoking IO callback on",callback,"for request",url, t); callback.onError(X_Util.unwrap(t));