List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:com.qwazr.webapps.transaction.StaticManager.java
public static void load(File dataDir) throws IOException { if (INSTANCE != null) throw new IOException("Already loaded"); INSTANCE = new StaticManager(dataDir); }
From source file:Main.java
private static int safelyConnect(HttpURLConnection connection) throws IOException { try {/*from w ww . j av a2s. c om*/ connection.connect(); } catch (NullPointerException e) { // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 throw new IOException(e); } catch (IllegalArgumentException e) { // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 throw new IOException(e); } catch (IndexOutOfBoundsException e) { // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 throw new IOException(e); } catch (SecurityException e) { // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 throw new IOException(e); } try { return connection.getResponseCode(); } catch (NullPointerException e) { // this is maybe this Android bug: http://code.google.com/p/android/issues/detail?id=15554 throw new IOException(e); } catch (StringIndexOutOfBoundsException e) { // this is maybe this Android bug: http://code.google.com/p/android/issues/detail?id=15554 throw new IOException(e); } catch (IllegalArgumentException e) { // this is maybe this Android bug: http://code.google.com/p/android/issues/detail?id=15554 throw new IOException(e); } }
From source file:Main.java
/** * Deletes the contents of {@code dir}. Throws an IOException if any file * could not be deleted, or if {@code dir} is not a readable directory. *///from ww w . ja va 2 s. c om static void deleteContents(File dir) throws IOException { File[] files = dir.listFiles(); if (files == null) { throw new IOException("not a readable directory: " + dir); } for (File file : files) { if (file.isDirectory()) { deleteContents(file); } if (!file.delete()) { throw new IOException("failed to delete file: " + file); } } }
From source file:Main.java
/** * Prepares the destination directory by creating directories if needed * @param destination The destination directory * @throws IOException//from www . j av a2s . c o m */ public static void prepareDestination(File destination) throws IOException { File parent = destination.getParentFile(); if (!parent.exists()) { if (!parent.mkdirs()) { throw new IOException("Unable to create destination directory: " + parent.getPath()); } } }
From source file:Main.java
/** * Creates a document from the given xml bytes. * @return The desired document. Never returns null but throws some Exception. * @throws ParserConfigurationException, IOException, SAXException *//*w ww . j a v a2s .c o m*/ public static Document getDocument(byte[] xml) throws ParserConfigurationException, IOException, SAXException { if (xml != null) { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // factory.setNamespaceAware( true ); // factory.setValidating( true ); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.parse(new ByteArrayInputStream(xml)); return document; } throw new IOException("No xml data"); }
From source file:FileHelper.java
public static boolean areInSync(File source, File destination) throws IOException { if (source.isDirectory()) { if (!destination.exists()) { return false; } else if (!destination.isDirectory()) { throw new IOException("Source and Destination not of the same type:" + source.getCanonicalPath() + " , " + destination.getCanonicalPath()); }// w ww. jav a 2 s .c om String[] sources = source.list(); Set<String> srcNames = new HashSet<String>(Arrays.asList(sources)); String[] dests = destination.list(); // check for files in destination and not in source for (String fileName : dests) { if (!srcNames.contains(fileName)) { return false; } } boolean inSync = true; for (String fileName : sources) { File srcFile = new File(source, fileName); File destFile = new File(destination, fileName); if (!areInSync(srcFile, destFile)) { inSync = false; break; } } return inSync; } else { if (destination.exists() && destination.isFile()) { long sts = source.lastModified() / FAT_PRECISION; long dts = destination.lastModified() / FAT_PRECISION; return sts == dts; } else { return false; } } }
From source file:Main.java
static public void searchTag(XmlPullParser xpp, String tag) throws IOException, XmlPullParserException { int event;//from ww w . j ava 2 s . co m while ((event = xpp.next()) != XmlPullParser.END_DOCUMENT) { if (event == XmlPullParser.START_TAG && xpp.getName().equals(tag)) return; } throw new IOException(String.format("tag '%s' not found", tag)); }
From source file:Main.java
/** * Use an Xpath expression on the given node or document. * * @param _xpathExpression xpath expression string * @param _xmlDocumentOrNode a {@link Document} or {@link Node} object * @return NodeList never null/*from ww w . j a va2s . co m*/ * @throws IOException on error */ public static NodeList applyXpathExpressionToDocument(String _xpathExpression, Node _xmlDocumentOrNode) throws IOException { XPathFactory xfactory = XPathFactory.newInstance(); XPath xpath = xfactory.newXPath(); XPathExpression expr = null; try { expr = xpath.compile(_xpathExpression); } catch (XPathExpressionException _ex) { throw new IOException(_ex); } Object result = null; try { result = expr.evaluate(_xmlDocumentOrNode, XPathConstants.NODESET); } catch (Exception _ex) { throw new IOException(_ex); } return (NodeList) result; }
From source file:Main.java
protected static synchronized InputStream getAWebPage(URL url) throws ClientProtocolException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(url.toString()); try {//from w w w . j a va2 s . c o m //do the request HttpResponse response = httpClient.execute(httpGet, localContext); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != HTTP_STATUS_OK) { throw new IOException("Invalid response from the IKSU server! " + status.toString()); } //InputStream ist = response.getEntity().getContent(); return response.getEntity().getContent(); } catch (Exception e) { e.printStackTrace(); throw new ClientProtocolException("Protocol Exception! " + e.toString()); } }
From source file:com.aincc.ber.utils.FakeSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/*from w w w.j a va 2 s .co m*/ final SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new NaiveTrustManager() }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }