List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:org.guzz.web.context.spring.GuzzContextBeanFactory.java
public static GuzzContext createGuzzContext(Resource springResource) throws Exception { File file = springResource.getFile(); if (file == null) { throw new IOException("file is null. spring resource:" + springResource); }// w ww . j a v a 2 s . co m return new Configuration(file.getAbsolutePath()).newGuzzContext(); }
From source file:com.siniatech.siniautils.file.PathHelper.java
static public Path createFileWithContents(String pathString, String contents) throws IOException { Path path = FileSystems.getDefault().getPath(pathString); if (exists(path)) { throw new IOException("File " + pathString + " already exists."); } else {//from w w w .j ava 2 s . co m createFile(path); } try (BufferedWriter out = newBufferedWriter(path, Charset.defaultCharset())) { out.write(contents); return path; } }
From source file:Main.java
public static void skip(InputStream stream, int numBytes) throws IOException { numBytes -= stream.skip(numBytes);//w ww . j a v a 2 s. c o m for (; numBytes > 0; --numBytes) { if (stream.read() == -1) { throw new IOException("Unexpected end of stream"); } } }
From source file:Main.java
public static byte[] getContents(Document document) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {//from w w w .j a va 2 s . c om print(new PrintStream(out, true, "UTF-8"), document); return out.toByteArray(); } catch (Exception ex) { throw new IOException(ex.getLocalizedMessage()); } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } }
From source file:dev.meng.wikidata.util.http.HttpUtils.java
public static JSONObject queryForJSONResponse(URL url, String encoding) throws ProtocolException, IOException, StringConvertionException { JSONObject response = null;/* www . ja va 2s. c om*/ HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); if (connection.getResponseCode() == 200) { response = new JSONObject(StringUtils.inputStreamToString(connection.getInputStream(), encoding)); } else { throw new IOException("Error in opening: " + url + ", " + connection.getResponseCode() + " " + connection.getResponseMessage()); } return response; }
From source file:contrail.correct.TestFlashExtension.java
/** * @param args/* w ww . j a va 2 s . c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length != 1 || !args[0].contains("--flash_binary=")) { throw new IOException( "Specify --flash_binary parameter only\nArgument Example: --flash_binary=/path/to/flash/binary"); } TestFlashExtension tester = new TestFlashExtension(); tester.flashBinaryPath = args[0].substring(args[0].indexOf('=') + 1); if (tester.flashBinaryPath.trim().length() == 0) { throw new IOException( "Specify --flash_binary parameter only\nArgument Example: --flash_binary=/path/to/flash/binary"); } tester.testRun(); System.out.println("Execution Test PASSED"); tester.testMap(); System.out.println("Correctness Test PASSED"); }
From source file:Main.java
public static Document createDocument() throws IOException { DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;/*from www . j a va 2 s .c om*/ try { builder = dBF.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IOException("Error creating document builder. (" + e.getMessage() + ")"); } return builder.newDocument(); }
From source file:Main.java
public static void rmDir(File dir) throws IOException { if (dir.exists()) { File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { if (!files[i].delete()) { throw new IOException("could not delete " + files[i]); }/*from ww w . ja va2 s . c o m*/ } dir.delete(); } }
From source file:Main.java
public static void pretty(Document document, OutputStream outputStream, int indent) throws IOException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = null; try {//from w w w . ja va 2 s . co m transformer = transformerFactory.newTransformer(); } catch (TransformerConfigurationException e) { throw new RuntimeException(e); } transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); if (indent > 0) { transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent)); } Result result = new StreamResult(outputStream); Source source = new DOMSource(document); try { transformer.transform(source, result); } catch (TransformerException e) { throw new IOException(e); } }
From source file:Main.java
private static ImageInputStream getResourceAsStream(Class<?> aClass, String name) throws IOException { final InputStream is = aClass.getResourceAsStream(name); if (is == null) { throw new IOException(MessageFormat.format("resource {0} not found", name)); }// w w w. j a v a2s . c om return new FileCacheImageInputStream(is, null); }