List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:TestRdfToJsonConversion.java
private static boolean testFiles(String fnameNtriples, String fnameJson, String uri) { Map<String, Object> expected = null; Map<String, Object> actual = null; TestRdfToJsonConversion.logger.info("Convert " + fnameNtriples + " to " + fnameJson); try (InputStream in = new FileInputStream(new File(fnameNtriples)); InputStream out = new File(fnameJson).exists() ? new FileInputStream(new File(fnameJson)) : makeFile(fnameJson)) { actual = new JsonConverter(etikettMaker).convertLobidData(in, RDFFormat.NTRIPLES, uri, contextUrl); TestRdfToJsonConversion.logger.debug("Creates: "); TestRdfToJsonConversion.logger.debug(new ObjectMapper().writeValueAsString(actual)); TestRdfToJsonConversion.logger/* w w w . jav a 2 s . c o m*/ .info("Begin comparing files: " + fnameNtriples + " against " + fnameJson); try { expected = new ObjectMapper().readValue(out, Map.class); } // if file to test against not yet exists catch (FileNotFoundException | EOFException | JsonMappingException ef) { TestRdfToJsonConversion.logger.info( "Json file " + fnameJson + " to test against does not yet exist. Will create it now."); try { TestRdfToJsonConversion.logger .info("Creating: \n" + new ObjectMapper().writeValueAsString(actual)); JsonConverter.getObjectMapper().defaultPrettyPrintingWriter().writeValue(new File(fnameJson), actual); expected = new ObjectMapper().readValue(new File(fnameJson), Map.class); } catch (IOException e) { org.junit.Assert.assertFalse("Problems creating file " + e.getMessage(), true); } } } catch (IOException e) { e.printStackTrace(); } return new CompareJsonMaps().writeFileAndTestJson(new ObjectMapper().convertValue(actual, JsonNode.class), new ObjectMapper().convertValue(expected, JsonNode.class)); }
From source file:org.artags.android.app.widget.HttpUtils.java
private static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null;/*www . j a v a2 s. c o m*/ try { while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } } catch (IOException e) { Log.e(HttpUtils.class.getName(), e.getMessage()); } finally { try { is.close(); } catch (IOException e) { Log.e(HttpUtils.class.getName(), e.getMessage()); } } return sb.toString(); }
From source file:at.illecker.sentistorm.commons.util.io.IOUtils.java
public static void extractTarGz(InputStream inputTarGzStream, String outDir, boolean logging) { try {//ww w.ja va 2s . c om GzipCompressorInputStream gzIn = new GzipCompressorInputStream(inputTarGzStream); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); // read Tar entries TarArchiveEntry entry = null; while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) { if (logging) { LOG.info("Extracting: " + outDir + File.separator + entry.getName()); } if (entry.isDirectory()) { // create directory File f = new File(outDir + File.separator + entry.getName()); f.mkdirs(); } else { // decompress file int count; byte data[] = new byte[EXTRACT_BUFFER_SIZE]; FileOutputStream fos = new FileOutputStream(outDir + File.separator + entry.getName()); BufferedOutputStream dest = new BufferedOutputStream(fos, EXTRACT_BUFFER_SIZE); while ((count = tarIn.read(data, 0, EXTRACT_BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.close(); } } // close input stream tarIn.close(); } catch (IOException e) { LOG.error("IOException: " + e.getMessage()); } }
From source file:com.dalthed.tucan.TucanMobile.java
/** * Writes a note on the SD. Only Used for Development purposes * @param sFileName Filname/*from w w w.j a v a 2 s .c o m*/ * @param sBody content * @param mContext App Context */ public static void generateNoteOnSD(String sFileName, String sBody, Context mContext) { try { File root = new File(Environment.getExternalStorageDirectory(), "Notes"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, sFileName); FileWriter writer = new FileWriter(gpxfile); writer.append(sBody); writer.flush(); writer.close(); //Toast.makeText(mContext, "Saved", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); String importError = e.getMessage(); Log.e("TuCanMobile", importError); } }
From source file:com.adobe.cq.wcm.core.components.Utils.java
/** * Provided a {@code model} object and an {@code expectedJsonResource} identifying a JSON file in the class path, this method will * test the JSON export of the model and compare it to the JSON object provided by the {@code expectedJsonResource}. * * @param model the Sling Model * @param expectedJsonResource the class path resource providing the expected JSON object *///from ww w . j a va 2 s . c o m public static void testJSONExport(Object model, String expectedJsonResource) { Writer writer = new StringWriter(); ObjectMapper mapper = new ObjectMapper(); PageModuleProvider pageModuleProvider = new PageModuleProvider(); mapper.registerModule(pageModuleProvider.getModule()); DefaultMethodSkippingModuleProvider defaultMethodSkippingModuleProvider = new DefaultMethodSkippingModuleProvider(); mapper.registerModule(defaultMethodSkippingModuleProvider.getModule()); try { mapper.writer().writeValue(writer, model); } catch (IOException e) { fail(String.format("Unable to generate JSON export for model %s: %s", model.getClass().getName(), e.getMessage())); } JsonReader outputReader = Json.createReader(IOUtils.toInputStream(writer.toString())); InputStream is = Thread.currentThread().getContextClassLoader().getClass() .getResourceAsStream(expectedJsonResource); if (is != null) { JsonReader expectedReader = Json.createReader(is); assertEquals(expectedReader.read(), outputReader.read()); } else { fail("Unable to find test file " + expectedJsonResource + "."); } IOUtils.closeQuietly(is); }
From source file:alluxio.AlluxioTestDirectory.java
/** * Creates a directory with the given prefix inside the Alluxio temporary directory. * * @param prefix a prefix to use in naming the temporary directory * @return the created directory/* www .j a v a2 s. co m*/ */ public static File createTemporaryDirectory(String prefix) { final File file = new File(ALLUXIO_TEST_DIRECTORY, prefix + "-" + UUID.randomUUID()); if (!file.mkdir()) { throw new RuntimeException("Failed to create directory " + file.getAbsolutePath()); } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { try { alluxio.util.io.FileUtils.deletePathRecursively(file.getAbsolutePath()); } catch (IOException e) { LOG.warn("Failed to clean up Alluxio test directory {} : {}", file.getAbsolutePath(), e.getMessage()); } } })); return file; }
From source file:com.google.appsforyourdomain.provisioning.AppsUtil.java
/** * Posts the specified postContent to the urlString and * returns a JDOM Document object containing the XML response. * /*from w w w . j a v a2 s. com*/ * @param urlString URL destination * @param postContent XML request * @return a JDOM Document object containing the XML response */ public static Document postHttpRequest(String urlString, String postContent) throws AppsForYourDomainException { try { // Send content final HttpClient client = new HttpClient(); PostMethod method = new PostMethod(urlString); StringRequestEntity sre = new StringRequestEntity(postContent, "text/xml", "UTF-8"); method.setRequestEntity(sre); client.executeMethod(method); // Get response final SAXBuilder builder = new SAXBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); final Document doc = builder.build(rd); return doc; } catch (IOException e) { // error in URL Connection or reading response throw new ConnectionException(e.getMessage()); } catch (JDOMException e) { // error in converting to JDOM Document throw new ParseException(e.getMessage()); } }
From source file:Zip.java
/** * Reads a Jar file, displaying the attributes in its manifest and dumping * the contents of each file contained to the console. *//* w w w . ja v a 2s.co m*/ public static void readJarFile(String fileName) { JarFile jarFile = null; try { // JarFile extends ZipFile and adds manifest information jarFile = new JarFile(fileName); if (jarFile.getManifest() != null) { System.out.println("Manifest Main Attributes:"); Iterator iter = jarFile.getManifest().getMainAttributes().keySet().iterator(); while (iter.hasNext()) { Attributes.Name attribute = (Attributes.Name) iter.next(); System.out.println( attribute + " : " + jarFile.getManifest().getMainAttributes().getValue(attribute)); } System.out.println(); } // use the Enumeration to dump the contents of each file to the console System.out.println("Jar file entries:"); for (Enumeration e = jarFile.entries(); e.hasMoreElements();) { JarEntry jarEntry = (JarEntry) e.nextElement(); if (!jarEntry.isDirectory()) { System.out.println(jarEntry.getName() + " contains:"); BufferedReader jarReader = new BufferedReader( new InputStreamReader(jarFile.getInputStream(jarEntry))); while (jarReader.ready()) { System.out.println(jarReader.readLine()); } jarReader.close(); } } } catch (IOException ioe) { System.out.println("An IOException occurred: " + ioe.getMessage()); } finally { if (jarFile != null) { try { jarFile.close(); } catch (IOException ioe) { } } } }
From source file:com.tn.exam.util.web.springside.Struts2Utils.java
/** * .//from ww w . j ava2 s. com * eg. * render("text/plain", "hello", "encoding:GBK"); * render("text/plain", "hello", "no-cache:false"); * render("text/plain", "hello", "encoding:GBK", "no-cache:false"); * * @param headers ??header??"encoding:""no-cache:",UTF-8true. */ public static void render(final String contentType, final String content, final String... headers) { HttpServletResponse response = initResponseHeader(contentType, headers); try { response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.artags.android.app.widget.HttpUtils.java
/** * Gets an url content/*from w w w . j a v a 2 s. c om*/ * @param url The url * @return The content */ public static String getUrl(String url) { String result = ""; HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response; try { response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); } } catch (IOException ex) { Log.e(HttpUtils.class.getName(), ex.getMessage()); } return result; }