List of usage examples for java.lang Throwable getLocalizedMessage
public String getLocalizedMessage()
From source file:org.geoserver.rest.util.IOUtils.java
/** * Optimize version of copy method for file channels. * // w w w .j av a 2 s .com * @param bufferSize size of the temp buffer to use for this copy. * @param source the source {@link ReadableByteChannel}. * @param destination the destination {@link WritableByteChannel};. * @throws IOException in case something bad happens. */ public static void copyFileChannel(int bufferSize, FileChannel source, FileChannel destination) throws IOException { inputNotNull(source, destination); if (!source.isOpen() || !destination.isOpen()) throw new IllegalStateException("Source and destination channels must be open."); FileLock lock = null; try { lock = destination.lock(); final long sourceSize = source.size(); long pos = 0; while (pos < sourceSize) { // read and flip final long remaining = (sourceSize - pos); final int mappedZoneSize = remaining >= bufferSize ? bufferSize : (int) remaining; destination.transferFrom(source, pos, mappedZoneSize); // update zone pos += mappedZoneSize; } } finally { if (lock != null) { try { lock.release(); } catch (Throwable t) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.log(Level.INFO, t.getLocalizedMessage(), t); } } } }
From source file:org.geoserver.rest.util.IOUtils.java
/** * Copy the input file onto the output file using the specified buffer size. * /*from w w w. j a v a2s .c o m*/ * @param sourceFile the {@link File} to copy from. * @param destinationFile the {@link File} to copy to. * @param size buffer size. * @throws IOException in case something bad happens. */ public static void copyFile(File sourceFile, File destinationFile, int size) throws IOException { inputNotNull(sourceFile, destinationFile); if (!sourceFile.exists() || !sourceFile.canRead() || !sourceFile.isFile()) throw new IllegalStateException("Source is not in a legal state."); if (!destinationFile.exists()) { destinationFile.createNewFile(); } if (destinationFile.getAbsolutePath().equalsIgnoreCase(sourceFile.getAbsolutePath())) throw new IllegalArgumentException("Cannot copy a file on itself"); FileChannel source = null; FileChannel destination = null; source = new RandomAccessFile(sourceFile, "r").getChannel(); destination = new RandomAccessFile(destinationFile, "rw").getChannel(); try { copyFileChannel(size, source, destination); } finally { try { if (source != null) { try { source.close(); } catch (Throwable t) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.log(Level.INFO, t.getLocalizedMessage(), t); } } } finally { if (destination != null) { try { destination.close(); } catch (Throwable t) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.log(Level.INFO, t.getLocalizedMessage(), t); } } } } }
From source file:de.domjos.schooltools.helper.Helper.java
public static void printException(Context context, Throwable ex) { StringBuilder message = new StringBuilder(ex.getMessage() + "\n" + ex.toString()); for (StackTraceElement element : ex.getStackTrace()) { message.append(element.getFileName()).append(":").append(element.getClassName()).append(":") .append(element.getMethodName()).append(":").append(element.getLineNumber()); }//from w w w .j a v a 2s. c o m Log.e("Exception", message.toString(), ex); Log4JHelper.getLogger(context.getPackageName()).error("Exception", ex); Helper.createToast(context, ex.getLocalizedMessage(), false); }
From source file:uk.ac.ebi.phenotype.solr.indexer.IndexerManager.java
private static void logErrors(IndexerException ie) { // Print out the exceptions. if (ie.getLocalizedMessage() != null) { logger.error(ie.getLocalizedMessage()); logger.error("Exception is: ", ie); }//from w w w . j ava 2s.com int i = 0; Throwable t = ie.getCause(); while (t != null) { StringBuilder errMsg = new StringBuilder("Level " + i + ": "); if (t.getLocalizedMessage() != null) { errMsg.append(t.getLocalizedMessage()); } else { errMsg.append("<null>"); } logger.error(errMsg.toString()); logger.error("Exception is: ", ie); i++; t = t.getCause(); } }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.EclipseMessageUtils.java
/** * Creates the assert safe status./*from w w w.j a v a 2s.c o m*/ * * @param severity the severity * @param pluginId the plugin id * @param code the code * @param message the message * @param exception the exception * @return the status */ public static Status createAssertSafeStatus(int severity, String pluginId, int code, String message, Throwable exception) { if (!(severity == IStatus.OK || severity == IStatus.ERROR || severity == IStatus.WARNING || severity == IStatus.INFO || severity == IStatus.CANCEL)) { severity = IStatus.INFO; } if (StringUtils.isEmpty(pluginId)) { pluginId = UtilsActivator.PLUGIN_ID; } if (StringUtils.isEmpty(message)) { if (exception != null && !StringUtils.isEmpty(exception.getLocalizedMessage())) { message = exception.getLocalizedMessage(); } else { message = ERROR_MESSAGE_UNKNOWN; } } /*if (exception == null) { exception = new Exception(ERROR_MESSAGE_UNKNOWN); }*/ return new Status(severity, pluginId, code, message, exception); }
From source file:org.marketcetera.util.ws.wrappers.WrapperTestBase.java
protected static void assertThrowable(Throwable expected, Throwable actual, boolean proxyUsed) { if ((actual == null) || (expected == null)) { assertEquals(expected, actual);/*from w w w . j a v a 2 s . c om*/ return; } if (proxyUsed) { assertEquals(RemoteProxyException.class, actual.getClass()); if (expected instanceof I18NThrowable) { assertEquals(((I18NThrowable) expected).getLocalizedDetail(), actual.getMessage()); ActiveLocale.setProcessLocale(Locale.FRENCH); assertEquals(((I18NThrowable) expected).getLocalizedDetail(), actual.getMessage()); ActiveLocale.setProcessLocale(Locale.ROOT); } else { assertEquals(expected.getLocalizedMessage(), actual.getMessage()); } } else { assertEquals(expected.getClass(), actual.getClass()); assertEquals(expected.getMessage(), actual.getMessage()); } assertEquals(expected.toString(), actual.toString()); assertArrayEquals(ExceptionUtils.getStackFrames(expected), ExceptionUtils.getStackFrames(actual)); }
From source file:org.exoplatform.services.jcr.impl.core.query.sql.JCRSQLQueryBuilder.java
/** * Creates a <code>QueryNode</code> tree from a SQL <code>statement</code> * using the passed query node <code>factory</code>. * * @param statement the SQL statement.//from w ww . jav a 2s .co m * @param resolver the namespace resolver to use. * @return the <code>QueryNode</code> tree. * @throws InvalidQueryException if <code>statement</code> is malformed. */ public static QueryRootNode createQuery(String statement, LocationFactory resolver, QueryNodeFactory factory) throws InvalidQueryException { try { // get parser JCRSQLParser parser; synchronized (parsers) { parser = (JCRSQLParser) parsers.get(resolver); if (parser == null) { parser = new JCRSQLParser(new StringReader(statement)); //parser.setNameResolver(resolver); parser.setLocationfactory(resolver); parsers.put(resolver, parser); } } JCRSQLQueryBuilder builder; // guard against concurrent use within same session synchronized (parser) { parser.ReInit(new StringReader(statement)); builder = new JCRSQLQueryBuilder(parser.Query(), resolver, factory); } return builder.getRootNode(); } catch (ParseException e) { throw new InvalidQueryException(e.getMessage()); } catch (IllegalArgumentException e) { throw new InvalidQueryException(e.getMessage()); } catch (Throwable t) //NOSONAR { log.error(t.getLocalizedMessage(), t); // javacc parser may also throw an error in some cases throw new InvalidQueryException(t.getMessage(), t); } }
From source file:net.sf.jabref.exporter.FileActions.java
/** * Saves the database to file. Two boolean values indicate whether only * entries with a nonzero Globals.SEARCH value and only entries with a * nonzero Globals.GROUPSEARCH value should be saved. This can be used to * let the user save only the results of a search. False and false means all * entries are saved.//w ww . java 2 s.c o m */ public static SaveSession saveDatabase(BibDatabase database, MetaData metaData, File file, JabRefPreferences prefs, boolean checkSearch, boolean checkGroup, Charset encoding, boolean suppressBackup) throws SaveException { boolean backup = prefs.getBoolean(JabRefPreferences.BACKUP); if (suppressBackup) { backup = false; } SaveSession session; BibEntry exceptionCause = null; try { session = new SaveSession(file, encoding, backup); } catch (Throwable e) { if (encoding != null) { LOGGER.error("Error from encoding: '" + encoding.displayName(), e); } // we must catch all exceptions to be able notify users that // saving failed, no matter what the reason was // (and they won't just quit JabRef thinking // everything worked and loosing data) throw new SaveException(e.getMessage(), e.getLocalizedMessage()); } Map<String, EntryType> types = new TreeMap<>(); // Get our data stream. This stream writes only to a temporary file, // until committed. try (VerifyingWriter writer = session.getWriter()) { // Write signature. FileActions.writeBibFileHeader(writer, encoding); // Write preamble if there is one. FileActions.writePreamble(writer, database.getPreamble()); // Write strings if there are any. FileActions.writeStrings(writer, database); // Write database entries. Take care, using CrossRefEntry- // Comparator, that referred entries occur after referring // ones. Apart from crossref requirements, entries will be // sorted as they appear on the screen. List<BibEntry> sorter = FileActions.getSortedEntries(database, metaData, null, true); BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), true); for (BibEntry entry : sorter) { exceptionCause = entry; // Check if we must write the type definition for this // entry, as well. Our criterion is that all non-standard // types (*not* customized standard types) must be written. EntryType entryType = entry.getType(); if (EntryTypes.getStandardType(entryType.getName()) == null) { types.put(entryType.getName(), entryType); } // Check if the entry should be written. boolean write = true; if (checkSearch && !FileActions.nonZeroField(entry, BibtexFields.SEARCH)) { write = false; } if (checkGroup && !FileActions.nonZeroField(entry, BibtexFields.GROUPSEARCH)) { write = false; } if (write) { bibtexEntryWriter.write(entry, writer); } } // Write meta data. if (metaData != null) { metaData.writeMetaData(writer); } // Write type definitions, if any: if (!types.isEmpty()) { for (Map.Entry<String, EntryType> stringBibtexEntryTypeEntry : types.entrySet()) { EntryType type = stringBibtexEntryTypeEntry.getValue(); if (type instanceof CustomEntryType) { CustomEntryType tp = (CustomEntryType) type; CustomEntryTypesManager.save(tp, writer); } } } //finally write whatever remains of the file, but at least a concluding newline if ((database.getEpilog() != null) && !(database.getEpilog().isEmpty())) { writer.write(database.getEpilog()); } else { writer.write(Globals.NEWLINE); } } catch (IOException ex) { LOGGER.error("Could not write file", ex); session.cancel(); // repairAfterError(file, backup, INIT_OK); throw new SaveException(ex.getMessage(), ex.getLocalizedMessage(), exceptionCause); } return session; }
From source file:org.jboss.tools.project.examples.internal.ProjectExamplesActivator.java
public static void log(Throwable e) { IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e); ProjectExamplesActivator.getDefault().getLog().log(status); }
From source file:org.apache.kylin.common.util.MailTemplateProvider.java
public String buildMailContent(String tplKey, Map<String, Object> data) { try {/*from w ww . j a va2 s .co m*/ Template template = getTemplate(tplKey); if (template == null) { return "Cannot find email template for " + tplKey; } try (Writer out = new StringWriter()) { template.process(data, out); return out.toString(); } } catch (Throwable e) { return e.getLocalizedMessage(); } }