List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:com.axibase.tsd.driver.jdbc.strategies.Consumer.java
private static void processComments(StatementContext context, CharSequence comments) { if (StringUtils.isBlank(comments)) { return;/*from w w w .j av a2s .c om*/ } final String json = comments.toString(); if (logger.isTraceEnabled()) { logger.trace(json); } try { final Comments commentsObject = JsonMappingUtil.mapToComments(json); fillWarnings(commentsObject.getWarnings(), context); fillErrors(commentsObject.getErrors(), context); } catch (IOException e) { if (logger.isDebugEnabled()) { logger.debug("Wrong error format: {}", e.getMessage()); } } }
From source file:com.nineteendrops.tracdrops.client.core.Utils.java
public static byte[] getBinaryData(String fullFileName, TracProperties tracProperties) { File file = new File(fullFileName); if (!file.exists()) { throw new TracException(MessageUtils.getFullFileNameNotFoundMessage(fullFileName)); }/*from w w w . ja va2s .co m*/ if (!file.canRead()) { throw new TracException(MessageUtils.getFullFileNameNotFoundMessage(fullFileName)); } if (!file.isFile()) { throw new TracException(MessageUtils.getFullFileNameNotFoundMessage(fullFileName)); } int maxUploadSize = tracProperties.getIntegerProperty(TracProperties.ATTACHMENT_UPLOAD_MAX_SIZE); if (file.length() > maxUploadSize) { throw new TracException(MessageUtils.getMessage("core.file.size.exceeded", fullFileName, String.valueOf(maxUploadSize))); } byte[] binaryData; try { binaryData = new byte[(int) file.length()]; FileInputStream fis = new FileInputStream(file); fis.read(binaryData); fis.close(); } catch (IOException e) { throw new TracException(MessageUtils.registerErrorLog(log, "core.unexpected.exception", e.getMessage()), e); } return binaryData; }
From source file:de.icongmbh.oss.maven.plugin.javassist.ClassnameExtractor.java
/** * Wrapping the iterator (as reference) of class file names and extract full qualified class name * on//ww w . j a v a2s . com * {@link Iterator#next()}. * <p> * It is possible that {@link Iterator#hasNext()} returns {@code true} and {@link Iterator#next()} * returns {@code null}. * </p> * * @param parentDirectory to remove from {@code classFile} and maybe {@code null}. * @param classFileIterator to extract the names from. Must not be {@code null}. * @return iterator of full qualified class names based on passed classFiles or {@code null} * @see #extractClassNameFromFile(File, File) */ // DANGEROUS call by reference public static Iterator<String> iterateClassnames(final File parentDirectory, final Iterator<File> classFileIterator) { return new Iterator<String>() { @Override public boolean hasNext() { return classFileIterator == null ? false : classFileIterator.hasNext(); } @Override public String next() { final File classFile = classFileIterator.next(); try { // possible returns null return extractClassNameFromFile(parentDirectory, classFile); } catch (final IOException e) { throw new RuntimeException(e.getMessage()); } } @Override public void remove() { classFileIterator.remove(); } }; }
From source file:Main.java
private static org.w3c.dom.Document getXMLDocument(String url) { Document document = null;/* w w w. ja v a 2 s. c o m*/ DocumentBuilderFactory builderFactory; DocumentBuilder parser; // Try to load the document at the specified filepath into a DOM structure. // try { builderFactory = DocumentBuilderFactory.newInstance(); parser = builderFactory.newDocumentBuilder(); document = parser.parse(url); } catch (ParserConfigurationException p) { System.out.println("Error creating DOM parser."); System.out.println(" " + p.getMessage()); } catch (SAXException s) { System.out.println("XML document returned is not well-formed."); System.out.println(" URL : " + url); System.out.println(" " + s.getMessage()); } catch (IOException i) { System.out.println("Error accessing the stream."); System.out.println(" URL : " + url); System.out.println(" " + i.getMessage()); document = null; } return document; }
From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.ibm.test.IBMImporterTest.java
@BeforeClass public static void init() { try {/*from w ww . j a va 2 s . c om*/ persistenceApi = new ConfigurationParser(Constants.TEST_DB_CONFIG_PATH) .getDbInstance(Constants.DATABASE_TYPES.ORIENT_DB); } catch (IOException e) { fail("Unexpected exception occurred: " + e.getMessage()); } }
From source file:bs.ws1.dm.itg.App.java
private static String readFileIntoString(String file) { try {/*from w w w. jav a 2 s. co m*/ return StreamUtils.readStreamAsString(new FileInputStream(file)); } catch (IOException e) { LOG.log(Level.SEVERE, e.getMessage()); return "<no-message/>"; } }
From source file:com.ephesoft.dcma.util.WebServiceCaller.java
/** * Api to simply hit webservice. It will return true or false if Webservice hit was successful or unsuccessful respectively * /*from w ww . j av a2 s.c om*/ * @param serviceURL * @return */ private static boolean hitWebservice(final String serviceURL) { LOGGER.debug("Giving a hit at webservice URL."); boolean isActive = false; if (!EphesoftStringUtil.isNullOrEmpty(serviceURL)) { // Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. PostMethod method = new PostMethod(serviceURL); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { isActive = true; } else { LOGGER.info(EphesoftStringUtil.concatenate("Execute Method failed: ", method.getStatusLine())); } } catch (HttpException httpException) { LOGGER.error( EphesoftStringUtil.concatenate("Fatal protocol violation: ", httpException.getMessage())); } catch (IOException ioException) { LOGGER.error(EphesoftStringUtil.concatenate("Fatal transport error: ", ioException.getMessage())); } finally { // Release the connection. if (method != null) { method.releaseConnection(); } } } return isActive; }
From source file:com.ibm.jaql.lang.expr.hadoop.Util.java
/** * Modified from Hadoop's JobClient//from w w w. ja v a 2s. com * * @param taskId * @param taskLogUrl */ private static void logTaskLog(TaskAttemptID taskId, URL taskLogUrl) { try { URLConnection connection = taskLogUrl.openConnection(); BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream())); try { String logData = null; while ((logData = input.readLine()) != null) { if (logData.length() > 0) { LOG.info("[" + taskId + "]" + logData); } } } finally { input.close(); } } catch (IOException ioe) { LOG.warn("Error reading task output" + ioe.getMessage()); } }
From source file:com.wegas.log.neo4j.Neo4jUtils.java
/** * Extracts from the JSON result of a query the potential error message. * If no message is found null is returned. * * @param result the result of the query * @return the error message if an error occurred, null otherwise *//*from www . j a v a2 s . co m*/ protected static String extractErrorData(String result) { ObjectMapper om = new ObjectMapper(); try { JsonNode jn = om.readTree(result); JsonNode jnErr = jn.path("errors"); Iterator<JsonNode> ite1 = jnErr.elements(); String err = ""; while (ite1.hasNext()) { JsonNode jn1 = ite1.next(); err += ", " + jn1.path("message").asText(); } if ("".equals(err)) return null; return err.substring(2); } catch (IOException ioe) { logger.debug("Error in extractErrorData: " + ioe.getMessage()); } return null; }
From source file:com.rackspacecloud.blueflood.tools.ops.RollupTool.java
private static void rerollDataPerGran(Locator loc, Granularity gran, Range range, RollupType rollupType) { try {/* ww w . ja v a 2s. co m*/ //Get the source and destination column families Class<? extends Rollup> rollupClass = RollupType.classOf(rollupType, gran); ColumnFamily<Locator, Long> srcCF = CassandraModel.getColumnFamily(rollupClass, gran.finer()); ColumnFamily<Locator, Long> dstCF = CassandraModel.getColumnFamily(rollupClass, gran); System.out.println("Calculating rollups for " + gran.name() + ". Reading from: " + srcCF.getName() + ". Writing to: " + dstCF.getName()); //Get Rollup Computer Rollup.Type rollupComputer = RollupRunnable.getRollupComputer(rollupType, gran.finer()); //This needs some explanation: Here we take slots in the gran to which we are rolling up i.e dstgran //Then for each slot we grab the data from the srcCF, thus automatically grabbing the sub-slots in the finer gran //Also, we always use the supplied time range to find snapped times, because a rollup gran is always a multiple //of the grans that come before it. Iterable<Range> ranges = Range.rangesForInterval(gran, range.getStart(), range.getStop()); int count = 1; ArrayList<SingleRollupWriteContext> writeContexts = new ArrayList<SingleRollupWriteContext>(); for (Range r : ranges) { Points input; Rollup rollup = null; try { input = AstyanaxReader.getInstance().getDataToRoll(rollupClass, loc, r, srcCF); rollup = rollupComputer.compute(input); } catch (IOException ex) { System.err.println("IOException while getting points to roll " + ex.getMessage()); System.exit(-1); } writeContexts.add( new SingleRollupWriteContext(rollup, new SingleRollupReadContext(loc, r, gran), dstCF)); count++; } //Insert calculated Rollups back into destination CF try { AstyanaxWriter.getInstance().insertRollups(writeContexts); } catch (ConnectionException ex) { System.err.println("Connection exception while inserting rollups" + ex.getMessage()); System.exit(-1); } System.out.println("Rolled up " + count + " ranges of " + gran + "\n"); } catch (GranularityException e) { // Since we start rolling from 5m, we should never reach here. System.err.println("Unexpected exception encountered " + e.getMessage()); System.exit(-1); } }