List of usage examples for java.lang Throwable getLocalizedMessage
public String getLocalizedMessage()
From source file:org.geotools.gce.imagemosaic.FootprintUtils.java
/** * Write a footprint summary file (".fpt") given an input <String,Geometry> * map containing granule location and related geometry, and the index * shapefile store to associate footprints to granules. * //from www .ja va 2 s . c om * @param footprintSummaryFile * the output footprint summary file * @param footprintsLocationGeometryMap * the map containing <granuleLocation,footprintGeometry> pairs * @throws MalformedURLException In case the url we create internally for the mosaic index is wrong (should never happen) */ static void writeFootprintSummary(final File footprintSummaryFile, final File indexFile, final Map<String, Geometry> footprintsLocationGeometryMap) throws MalformedURLException { Utilities.ensureNonNull("footprintSummaryFile", footprintSummaryFile); Utilities.ensureNonNull("indexFile", indexFile); Utilities.ensureNonNull("footprintsLocationGeometryMap", footprintsLocationGeometryMap); if (footprintsLocationGeometryMap.isEmpty()) return; final ShapefileDataStore store = new ShapefileDataStore(indexFile.toURI().toURL()); if (footprintsLocationGeometryMap.isEmpty()) return; final String[] typeNames = store.getTypeNames(); if (typeNames.length <= 0) { throw new IllegalArgumentException( "Problems when opening the shapefile, no typenames for the schema are defined"); } final String typeName = typeNames[0]; FileWriter footprintWriter = null; FeatureIterator<SimpleFeature> it = null; try { final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store.getFeatureSource(typeName); final FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures(); if (features == null) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("No features found in the shapefile"); } return; } // load the feature from the shapefile it = features.features(); if (!it.hasNext()) throw new IllegalArgumentException( "The provided FeatureCollection<SimpleFeatureType, SimpleFeature> or empty, it's impossible to create an index!"); footprintWriter = new FileWriter(footprintSummaryFile); final BufferedWriter writer = new BufferedWriter(footprintWriter); final WKTWriter geometryWriter = new WKTWriter(); // Scan the index shapefile to get granules location while (it.hasNext()) { final SimpleFeature feature = it.next(); final String location = (String) feature.getAttribute("location"); if (location != null && location.trim().length() > 0) { final String locationKey = location; // Check if a footprint exist in the map for this granule if (footprintsLocationGeometryMap.containsKey(locationKey)) { // Build a featureID=Geometry pair and write it in // the Footprint summary file final String idGeometryPair = FootprintUtils.buildIDGeometryPair( footprintsLocationGeometryMap, feature.getID(), locationKey, geometryWriter); writer.write(idGeometryPair); } } } writer.flush(); writer.close(); } catch (Throwable e) { // ignore exception if (LOGGER.isLoggable(Level.FINEST)) LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e); } finally { try { if (it != null) { it.close(); } } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINEST)) LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e); } try { if (footprintWriter != null) { footprintWriter.flush(); footprintWriter.close(); } } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINEST)) LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e); IOUtils.closeQuietly(footprintWriter); } footprintWriter = null; try { store.dispose(); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINEST)) LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e); } } }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.EclipseMessageUtils.java
/** * Creates the error status./*from w w w . j ava 2 s. c om*/ * * @param thrown the thrown * @return an instance of <code>IStatus</code> with Error severity level */ public static IStatus createErrorStatus(Throwable thrown) { return createErrorStatus(UtilsActivator.SOA_PLUGIN_ID, thrown.getLocalizedMessage(), thrown); }
From source file:com.seleniumtests.reporter.reporters.CommonReporter.java
/** * Method to generate the formated stacktrace * @param exception Exception to format * @param title title of the exception * @param contentBuffer /*from w ww . java2 s . c om*/ * @param format format to use to encode ('html', 'csv', 'xml', 'json') */ public static void generateTheStackTrace(final Throwable exception, final String title, final StringBuilder contentBuffer, String format) { contentBuffer.append(exception.getClass() + ": " + StringUtility.encodeString(title, format) + "\n"); StackTraceElement[] s1 = exception.getStackTrace(); Throwable t2 = exception.getCause(); if (t2 == exception) { t2 = null; } for (int x = 0; x < s1.length; x++) { String message = filterStackTrace(s1[x].toString()); if (message != null) { contentBuffer.append("\nat " + StringUtility.encodeString(message, format)); } } if (t2 != null) { generateTheStackTrace(t2, "Caused by " + t2.getLocalizedMessage(), contentBuffer, format); } }
From source file:org.arakhne.afc.ui.android.filechooser.FileChooserActivity.java
private static FileFilter getFileFilterParameter(String name, FileFilter defaultValue, Bundle... bundles) { for (Bundle b : bundles) { if (b != null) { String classname = b.getString(name); if (classname != null) { try { Class<?> type = Class.forName(classname); if (FileFilter.class.isAssignableFrom(type)) { return (FileFilter) type.newInstance(); }// ww w. ja v a 2s . c om } catch (Throwable e) { Log.d("FILE_CHOOSER", e.getLocalizedMessage(), e); } } } } return defaultValue; }
From source file:org.arakhne.afc.ui.android.filechooser.FileChooserActivity.java
private static FileChooserIconSelector getIconSelectorParameter(String name, FileChooserIconSelector defaultValue, Bundle... bundles) { for (Bundle b : bundles) { if (b != null) { String classname = b.getString(name); if (classname != null) { try { Class<?> type = Class.forName(classname); if (FileChooserIconSelector.class.isAssignableFrom(type)) { return (FileChooserIconSelector) type.newInstance(); }// www. j a v a2s. c o m } catch (Throwable e) { Log.d("FILE_CHOOSER", e.getLocalizedMessage(), e); } } } } return defaultValue; }
From source file:it.geosolutions.tools.io.file.Copy.java
/** * Copy the input file onto the output file using the specified buffer size. * /*from ww w .j a va 2 s . 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 { Objects.notNull(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"); RandomAccessFile s = null, d = null; FileChannel source = null; FileChannel destination = null; try { s = new RandomAccessFile(sourceFile, "r"); source = s.getChannel(); d = new RandomAccessFile(destinationFile, "rw"); destination = d.getChannel(); IOUtils.copyFileChannel(size, source, destination); } finally { if (source != null) { try { source.close(); } catch (Throwable t) { if (LOGGER.isInfoEnabled()) LOGGER.info(t.getLocalizedMessage(), t); } } if (s != null) { try { s.close(); } catch (Throwable t) { if (LOGGER.isInfoEnabled()) LOGGER.info(t.getLocalizedMessage(), t); } } if (destination != null) { try { destination.close(); } catch (Throwable t) { if (LOGGER.isInfoEnabled()) LOGGER.info(t.getLocalizedMessage(), t); } } if (d != null) { try { d.close(); } catch (Throwable t) { if (LOGGER.isInfoEnabled()) LOGGER.info(t.getLocalizedMessage(), t); } } } }
From source file:org.apache.openejb.math.MathRuntimeException.java
/** * Constructs a new <code>IllegalArgumentException</code> with specified nested * <code>Throwable</code> root cause. * * @param rootCause the exception or error that caused this exception * to be thrown.//from w w w . j a v a 2s. c om * @return built exception */ public static IllegalArgumentException createIllegalArgumentException(final Throwable rootCause) { final IllegalArgumentException iae = new IllegalArgumentException(rootCause.getLocalizedMessage()); iae.initCause(rootCause); return iae; }
From source file:org.marketcetera.strategyagent.StrategyAgent.java
/** * Return the exception message from the supplied Throwable. * * @param inThrowable the throwable whose message needs to be returned. * * @return the throwable message./*from w ww .java 2s . c om*/ */ private static String getMessage(Throwable inThrowable) { if (inThrowable instanceof I18NException) { return ((I18NException) inThrowable).getLocalizedDetail(); } else { return inThrowable.getLocalizedMessage(); } }
From source file:it.geosolutions.geobatch.geotiff.publish.GeotiffGeoServerAction.java
/** * If configuration.isFailIgnore and publish fails return false otherwise * true.<br>/*from w w w . j a v a 2 s.c om*/ * If ! configuration.isFailIgnore and publish fails throws ActionException * otherwise return true.<br> * * @param inputFile the file to publish * @param configuration the configuration to use * @return true if success, false otherwise. * @throws Exception */ private static boolean publishGeoTiff(File inputFile, GeoServerActionConfiguration configuration) throws Exception { final String inputFileName = inputFile.getName(); final String filePrefix = FilenameUtils.getBaseName(inputFile.getName()); final String fileSuffix = FilenameUtils.getExtension(inputFile.getName()); String baseFileName = null; final String fileNameFilter = configuration.getStoreFilePrefix(); if (fileNameFilter != null) { if ((filePrefix.equals(fileNameFilter) || filePrefix.matches(fileNameFilter)) && ("tif".equalsIgnoreCase(fileSuffix) || "tiff".equalsIgnoreCase(fileSuffix))) { // etj: are we missing something here? baseFileName = filePrefix; } } else if ("tif".equalsIgnoreCase(fileSuffix) || "tiff".equalsIgnoreCase(fileSuffix)) { baseFileName = filePrefix; } if (baseFileName == null) { final String message = "Unable to find a fileName for '" + inputFileName + "'"; if (LOGGER.isErrorEnabled()) LOGGER.error(message); if (!configuration.isFailIgnored()) throw new IllegalStateException(message); } // generate the coveragestore id final String coverageStoreId = FilenameUtils.getBaseName(inputFileName); // // // creating coverageStore // // GeoTiffReader coverageReader = null; // Trying to read the GeoTIFF to make sure it is correct CoordinateReferenceSystem crs = null; Integer epsgCode = null; try { if (!FORMAT.accepts(inputFile)) { final String message = "No valid GeoTIFF File found for this Data Flow!"; if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } if (!configuration.isFailIgnored()) throw new IllegalStateException(message); } coverageReader = (GeoTiffReader) FORMAT.getReader(inputFile); if (coverageReader == null) { final String message = "No valid GeoTIFF File found for this Data Flow!"; if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } if (!configuration.isFailIgnored()) throw new IllegalStateException(message); } // get the CRS or go back to the default one as per the // configuration if we cannot find one crs = coverageReader.getCrs(); if (crs != null) { epsgCode = CRS.lookupEpsgCode(crs, false); } } finally { if (coverageReader != null) { try { coverageReader.dispose(); } catch (Throwable e) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(e.getLocalizedMessage(), e); } } } } // // SENDING data to GeoServer via REST protocol. // boolean sent = false; GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(configuration.getGeoserverURL(), configuration.getGeoserverUID(), configuration.getGeoserverPWD()); GeoServerRESTReader reader = new GeoServerRESTReader(configuration.getGeoserverURL(), configuration.getGeoserverUID(), configuration.getGeoserverPWD()); WorkspaceUtils.createWorkspace(reader, publisher, configuration.getDefaultNamespace(), configuration.getDefaultNamespaceUri()); // check transfer method String transferMethod = configuration.getDataTransferMethod(); if (transferMethod == null) { transferMethod = "DIRECT"; // default one } // decide CRS // default crs final String defaultCRS = configuration.getCrs(); String finalEPSGCode = defaultCRS; // retain original CRS if the code is there if (epsgCode == null) { // we do not have a valid EPSG code if (defaultCRS == null) { final String message = "Input file has no CRS neither the configuration provides a default one"; if (LOGGER.isInfoEnabled()) { LOGGER.info(message); } if (!configuration.isFailIgnored()) throw new ActionException(GeotiffGeoServerAction.class, message); return false; } } else { finalEPSGCode = "EPSG:" + epsgCode; } // decide CRS management ProjectionPolicy projectionPolicy = ProjectionPolicy.NONE; if (crs == null) { // we do not have a valid CRS, we use the default one projectionPolicy = ProjectionPolicy.FORCE_DECLARED; } else // we DO have a valid CRS if (epsgCode == null) { // we do not have a CRS with a valid EPSG code, let's reproject on // the fly projectionPolicy = ProjectionPolicy.REPROJECT_TO_DECLARED; } GSCoverageEncoder coverage = new GSCoverageEncoder(); coverage.setName(configuration.getLayerName() == null ? coverageStoreId : configuration.getLayerName()); coverage.setTitle(configuration.getTitle()); coverage.setDescription(configuration.getLayerDescription()); coverage.setSRS(finalEPSGCode); coverage.setProjectionPolicy(projectionPolicy); coverage.setAbstract(configuration.getLayerAbstract()); // GSWorkspaceEncoder workspace=new GSWorkspaceEncoder(configuration.getDefaultNamespace()); GSLayerEncoder layer = new GSLayerEncoder(); layer.setDefaultStyle(configuration.getDefaultStyle() != null ? configuration.getDefaultStyle() : "raster"); layer.setQueryable(configuration.getQueryable()); if ("DIRECT".equalsIgnoreCase(transferMethod)) { // Transferring the fil sent = publisher.publishGeoTIFF(configuration.getDefaultNamespace(), configuration.getStoreName() == null ? coverageStoreId : configuration.getStoreName(), configuration.getLayerName() == null ? coverageStoreId : configuration.getLayerName(), inputFile, finalEPSGCode, projectionPolicy, configuration.getDefaultStyle() != null ? configuration.getDefaultStyle() : "raster", null); } else if ("EXTERNAL".equalsIgnoreCase(configuration.getDataTransferMethod())) { sent = publisher.publishExternalGeoTIFF(configuration.getDefaultNamespace(), configuration.getStoreName() == null ? coverageStoreId : configuration.getStoreName(), inputFile, coverage, layer) != null ? true : false; // sent = publisher.publishExternalGeoTIFF(configuration.getDefaultNamespace(),// workspace // configuration.getStoreName() == null // ? coverageStoreId : configuration.getStoreName(), // inputFile, // configuration.getLayerName() == null // ? coverageStoreId : configuration.getLayerName(), // finalEPSGCode, // projectionPolicy, // configuration.getDefaultStyle() != null ? configuration.getDefaultStyle() : "raster"); } else { final String message = "FATAL -> Unknown transfer method " + configuration.getDataTransferMethod(); if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } sent = false; } if (sent) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Coverage SUCCESSFULLY sent to GeoServer!"); } return true; } else { final String message = "Coverage was NOT sent to GeoServer due to connection errors!"; if (LOGGER.isInfoEnabled()) { LOGGER.info(message); } if (!configuration.isFailIgnored()) throw new ActionException(GeotiffGeoServerAction.class, message); } return false; }
From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java
private static JSONObject toJSONError(Throwable x, JSONObject log) { final StringWriter stackTrace = new StringWriter(); x.printStackTrace(new PrintWriter(stackTrace)); final JSONObject error = new JSONObject(); try {//w ww .j a v a2 s . co m error.put("error", x.getClass().getSimpleName()); error.put("exception", x.getClass().getName()); error.put("message", x.getLocalizedMessage()); error.put("stackTrace", stackTrace.toString()); if (log != null) { error.put("log", log); } } catch (JSONException e) { throw new AssertionError(e); } return error; }