List of usage examples for java.io IOException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.kylinolap.rest.service.AclService.java
public AclService() { String metadataUrl = KylinConfig.getInstanceFromEnv().getMetadataUrl(); // split TABLE@HBASE_URL int cut = metadataUrl.indexOf('@'); tableNameBase = cut < 0 ? DEFAULT_TABLE_PREFIX : metadataUrl.substring(0, cut); hbaseUrl = cut < 0 ? metadataUrl : metadataUrl.substring(cut + 1); aclTableName = tableNameBase + ACL_TABLE_NAME; fieldAces.setAccessible(true);// w w w. ja v a2 s . c o m fieldAcl.setAccessible(true); try { HBaseConnection.createHTableIfNeeded(hbaseUrl, aclTableName, ACL_INFO_FAMILY, ACL_ACES_FAMILY); } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); } }
From source file:com.tc.server.TCServerImpl.java
@Override public String getConfig() { InputStream is = null;//from w ww .j av a 2 s .c om try { is = this.configurationSetupManager.rawConfigFile(); return IOUtils.toString(is); } catch (IOException ioe) { return ioe.getLocalizedMessage(); } finally { IOUtils.closeQuietly(is); } }
From source file:com.kylinolap.rest.service.AclService.java
@Override public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException { HTableInterface htable = null;/*from ww w. j a v a 2 s .c o m*/ try { htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName); Delete delete = new Delete(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier()))); List<ObjectIdentity> children = findChildren(objectIdentity); if (!deleteChildren && children.size() > 0) { throw new ChildrenExistException("Children exists for " + objectIdentity); } for (ObjectIdentity oid : children) { deleteAcl(oid, deleteChildren); } htable.delete(delete); htable.flushCommits(); logger.debug("ACL of " + objectIdentity + " deleted successfully."); } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); } finally { IOUtils.closeQuietly(htable); } }
From source file:it.geosolutions.geobatch.actions.xstream.XstreamAction.java
public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { // the output final Queue<EventObject> ret = new LinkedList<EventObject>(); listenerForwarder.started();//from w w w.j a va2 s . co m while (events.size() > 0) { final EventObject event = events.remove(); if (event == null) { final String message = "The passed event object is null"; if (LOGGER.isWarnEnabled()) LOGGER.warn(message); if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } if (event instanceof FileSystemEvent) { // generate an object final File sourceFile = File.class.cast(event.getSource()); if (!sourceFile.exists() || !sourceFile.canRead()) { final String message = "XstreamAction.adapter(): The passed FileSystemEvent " + "reference to a not readable or not existent file: " + sourceFile.getAbsolutePath(); if (LOGGER.isWarnEnabled()) LOGGER.warn(message); if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } FileInputStream inputStream = null; try { inputStream = new FileInputStream(sourceFile); final Map<String, String> aliases = conf.getAlias(); if (aliases != null && aliases.size() > 0) { for (String alias : aliases.keySet()) { final Class<?> clazz = Class.forName(aliases.get(alias)); xstream.alias(alias, clazz); } } listenerForwarder.setTask("Converting file to a java object"); // deserialize final Object res = xstream.fromXML(inputStream); // generate event final EventObject eo = new EventObject(res); // append to the output ret.add(eo); } catch (XStreamException e) { // the object cannot be deserialized if (LOGGER.isErrorEnabled()) LOGGER.error("The passed FileSystemEvent reference to a not deserializable file: " + sourceFile.getAbsolutePath(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } catch (Throwable e) { // the object cannot be deserialized if (LOGGER.isErrorEnabled()) LOGGER.error("XstreamAction.adapter(): " + e.getLocalizedMessage(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } finally { IOUtils.closeQuietly(inputStream); } } else { // try to serialize // build the output absolute file name File outputDir; try { outputDir = new File(conf.getOutput()); // the output if (!outputDir.isAbsolute()) outputDir = it.geosolutions.tools.commons.file.Path.findLocation(outputDir, getTempDir()); if (!outputDir.exists()) { if (!outputDir.mkdirs()) { final String message = "Unable to create the ouptut dir named: " + outputDir.toString(); if (LOGGER.isInfoEnabled()) LOGGER.info(message); if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Output dir name: " + outputDir.toString()); } } catch (NullPointerException npe) { final String message = "Unable to get the output file path from :" + conf.getOutput(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, npe); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(npe); throw new ActionException(this, npe.getLocalizedMessage()); } } final File outputFile; try { outputFile = File.createTempFile(conf.getOutput(), null, outputDir); } catch (IOException ioe) { final String message = "Unable to build the output file writer: " + ioe.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, ioe); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(ioe); throw new ActionException(this, ioe.getLocalizedMessage()); } } // try to open the file to write into FileWriter fw = null; try { listenerForwarder.setTask("Serializing java object to " + outputFile); fw = new FileWriter(outputFile); final Map<String, String> aliases = conf.getAlias(); if (aliases != null && aliases.size() > 0) { for (String alias : aliases.keySet()) { final Class<?> clazz = Class.forName(aliases.get(alias)); xstream.alias(alias, clazz); } } xstream.toXML(event.getSource(), fw); } catch (XStreamException e) { if (LOGGER.isErrorEnabled()) LOGGER.error( "The passed event object cannot be serialized to: " + outputFile.getAbsolutePath(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } catch (Throwable e) { // the object cannot be deserialized if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } finally { IOUtils.closeQuietly(fw); } // add the file to the queue ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED)); } } listenerForwarder.completed(); return ret; }
From source file:com.android.im.imps.HttpDataChannel.java
/** * Sends a primitive to the IMPS server through HTTP. * * @param p The primitive to send./*from w w w.j av a 2 s. c o m*/ */ private void doSendPrimitive(Primitive p) { String errorInfo = null; int retryCount = 0; long retryDelay = INIT_RETRY_DELAY_MS; while (retryCount < MAX_RETRY_COUNT) { try { trySend(p); return; } catch (IOException e) { errorInfo = e.getLocalizedMessage(); String type = p.getType(); if (ImpsTags.Login_Request.equals(type) || ImpsTags.Logout_Request.equals(type)) { // we don't retry to send login/logout request. The request // might be sent to the server successfully but we failed to // get the response from the server. Retry in this case might // cause multiple login which is not allowed by some server. break; } if (p.getTransactionMode() == TransactionMode.Response) { // Ignore the failure of sending response to the server since // it's only an acknowledgment. When we get here, the // primitive might have been sent successfully but failed to // get the http response. The server might or might not send // the request again if it does not receive the acknowledgment, // the client is ok to either case. return; } retryCount++; // sleep for a while and retry to send the primitive in a new // transaction if we havn't met the max retry count. if (retryCount < MAX_RETRY_COUNT) { mTxManager.reassignTransactionId(p); Log.w(ImpsLog.TAG, "Send primitive failed, retry after " + retryDelay + "ms"); synchronized (mRetryLock) { try { mRetryLock.wait(retryDelay); } catch (InterruptedException ignore) { } if (mStopRetry) { break; } } retryDelay = retryDelay * 2; if (retryDelay > MAX_RETRY_DELAY_MS) { retryDelay = MAX_RETRY_DELAY_MS; } } } } Log.w(ImpsLog.TAG, "Failed to send primitive after " + MAX_RETRY_COUNT + " retries"); mTxManager.notifyErrorResponse(p.getTransactionID(), ImErrorInfo.NETWORK_ERROR, errorInfo); }
From source file:com.kylinolap.rest.service.AclService.java
@Override public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) { List<ObjectIdentity> oids = new ArrayList<ObjectIdentity>(); HTableInterface htable = null;//from ww w . j a v a 2 s . c o m try { htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName); Scan scan = new Scan(); SingleColumnValueFilter parentFilter = new SingleColumnValueFilter(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN), CompareOp.EQUAL, domainObjSerializer.serialize(new DomainObjectInfo(parentIdentity))); parentFilter.setFilterIfMissing(true); scan.setFilter(parentFilter); ResultScanner scanner = htable.getScanner(scan); for (Result result = scanner.next(); result != null; result = scanner.next()) { String id = Bytes.toString(result.getRow()); String type = Bytes.toString(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN))); oids.add(new ObjectIdentityImpl(type, id)); } } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); } finally { IOUtils.closeQuietly(htable); } return oids; }
From source file:ca.phon.plugins.praat.TextGridManager.java
/** * Load the TextGrid for the given corpus, session * and recordId/*from w w w . j ava 2 s.c o m*/ * * @param corpus * @param session * @param recordId * * @return the TextGrid or <code>null</code> if not * found/loaded * * @deprecated since version 15 */ public TextGrid loadTextGrid(String recordId) { final String tgPath = textGridPath(recordId); TextGrid retVal = null; try { retVal = loadTextGrid(new File(tgPath)); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } return retVal; }
From source file:ca.phon.plugins.praat.TextGridManager.java
/** * Save text grid// www.j a va 2s . com * * @param textgrid * @param corpus * @param session * @param recordId * * @returns <code>true</code> if successful, <code>false</code> * otherwise * * @deprecated since version 15 */ public boolean saveTextGrid(TextGrid textgrid, String recordId) { final String tgPath = textGridPath(recordId); boolean retVal = false; try { saveTextGrid(textgrid, new File(tgPath)); retVal = true; } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } return retVal; }
From source file:it.geosolutions.geobatch.action.scripting.ScriptingAction.java
/** * Default execute method.../*from w w w . j a v a2s . c o m*/ */ @SuppressWarnings("unchecked") public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException { try { listenerForwarder.started(); // // // data flow configuration and dataStore name must not be null. // // if (configuration == null) { throw new ActionException(this, "Configuration is null."); } final String scriptName = it.geosolutions.tools.commons.file.Path .findLocation(configuration.getScriptFile(), getConfigDir().getAbsolutePath()); if (scriptName == null) throw new ActionException(this, "Unable to locate the script file name: " + configuration.getScriptFile()); final File script = new File(scriptName); /** * Dynamic class-loading ... */ listenerForwarder.setTask("dynamic class loading ..."); final String moduleFolder = new File(script.getParentFile(), "jars").getAbsolutePath(); if (LOGGER.isInfoEnabled()) { LOGGER.info("Runtime class-loading from moduleFolder -> " + moduleFolder); } final File moduleDirectory = new File(moduleFolder); try { addFile(moduleDirectory.getParentFile()); addFile(moduleDirectory); } catch (IOException e) { throw new ActionException(this, e.getLocalizedMessage(), e); } final String classpath = System.getProperty("java.class.path"); final File[] moduleFiles = moduleDirectory.listFiles(); if (moduleFiles != null) { for (File moduleFile : moduleFiles) { final String name = moduleFile.getName(); if (name.endsWith(".jar")) { if (classpath.indexOf(name) == -1) { try { if (LOGGER.isInfoEnabled()) LOGGER.info("Adding: " + name); addFile(moduleFile); } catch (IOException e) { throw new ActionException(this, e.getLocalizedMessage(), e); } } } } } /** * Evaluating script ... */ listenerForwarder.setTask("evaluating script ..."); // Now, pass a different script context final ScriptContext newContext = new SimpleScriptContext(); final Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE); // add variables to the new engineScope // engineScope.put("eventList", events); // engineScope.put("runningContext", getRunningContext()); // add properties as free vars in script final Map<String, Object> props = configuration.getProperties(); if (props != null) { final Set<Entry<String, Object>> set = props.entrySet(); final Iterator<Entry<String, Object>> it = set.iterator(); while (it.hasNext()) { final Entry<String, ?> prop = it.next(); if (prop == null) { continue; } if (LOGGER.isInfoEnabled()) LOGGER.info(" Adding script property: " + prop.getKey() + " : " + prop.getValue()); engineScope.put(prop.getKey(), prop.getValue()); } } // read the script FileReader reader = null; try { reader = new FileReader(script); engine.eval(reader, engineScope); } catch (FileNotFoundException e) { throw new ActionException(this, e.getLocalizedMessage(), e); } finally { IOUtils.closeQuietly(reader); } final Invocable inv = (Invocable) engine; listenerForwarder.setTask("Executing script: " + script.getName()); // check for incoming event list if (events == null) { throw new ActionException(this, "Unable to start the script using a null incoming list of events"); } // call the script final Map<String, Object> argsMap = new HashedMap(); argsMap.put(ScriptingAction.CONFIG_KEY, configuration); argsMap.put(ScriptingAction.TEMPDIR_KEY, getTempDir()); argsMap.put(ScriptingAction.CONFIGDIR_KEY, getConfigDir()); argsMap.put(ScriptingAction.EVENTS_KEY, events); argsMap.put(ScriptingAction.LISTENER_KEY, listenerForwarder); final Map<String, Object> mapOut = (Map<String, Object>) inv.invokeFunction("execute", new Object[] { argsMap }); // checking output final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>(); if (mapOut == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Caution returned map from script " + configuration.getScriptFile() + " is null.\nSimulating an empty return list."); } return ret; } final Object obj = mapOut.get(ScriptingAction.RETURN_KEY); if (obj == null) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Caution returned object from script " + configuration.getScriptFile() + " is null.\nPassing an empty list to the next action!"); } return ret; } if (obj instanceof List) { final List<Object> list = (List<Object>) obj; for (final Object out : list) { if (out == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Caution returned object from script " + configuration.getScriptFile() + " is null.\nContinue with the next one."); } continue; } if (out instanceof FileSystemEvent) { FileSystemEvent ev = (FileSystemEvent) out; ret.add(ev); } else if (out instanceof File) { ret.add(new FileSystemEvent((File) out, FileSystemEventType.FILE_ADDED)); } else { final File file = new File(out.toString()); if (!file.exists() && LOGGER.isWarnEnabled()) { LOGGER.warn("Caution returned object from script " + configuration.getScriptFile() + " do not points to an existent file!"); } ret.add(new FileSystemEvent(file, FileSystemEventType.FILE_ADDED)); } } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error("Caution returned object from script " + configuration.getScriptFile() + " is not a valid List.\nPassing an empty list to the next action!"); } return ret; } listenerForwarder.setTask("Completed"); listenerForwarder.completed(); return ret; } catch (Exception t) { listenerForwarder.setTask("Completed with errors"); listenerForwarder.failed(t); throw new ActionException(this, t.getMessage(), t); } finally { engine = null; factory = null; } }
From source file:com.wooki.services.parsers.XHTMLToFormattingObjects.java
private void putInCache(String fileLocation, String systemId) { try {//from w w w .j a va 2s. c o m InputStream in = this.getClass().getResourceAsStream(fileLocation); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); byte[] input = null; int available = 0; while ((available = in.available()) > 0) { int result; input = new byte[available]; result = in.read(input); baos.write(input); if (result == -1) break; } byte[] dtd = baos.toByteArray(); Element element = new Element(systemId, dtd); cache.put(element); } catch (IOException e) { e.printStackTrace(); logger.error("Didn't manage to put " + fileLocation + " in the \"" + cacheName + "\" cache for systemId " + systemId); logger.error(e.getLocalizedMessage()); } }