List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:Main.java
/** * Loads an XML document from a File//from w ww . java2 s .c o m * @param uri The path the file. */ public static Document loadXmlDoc(final String uri) { Document result = null; try { File file = new File(uri); if (file.exists()) { result = loadXmlDoc(new FileInputStream(file)); } else { throw new IOException("File does not exist: " + file.getAbsolutePath()); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
From source file:com.sap.prd.mobile.ios.mios.FileUtils.java
public static void mkdirs(final File f) throws IOException { if (f.exists() && !f.isDirectory()) throw new IOException(String.format("'%s' does already exist but is not a directory.", f)); if (!f.exists() && !f.mkdirs()) throw new IOException("Could not create folder '" + f + "'."); }
From source file:Main.java
private static Reader getReader(InputStream is) throws IOException { Reader reader = new BufferedReader(new InputStreamReader(is)); char c[] = "<?".toCharArray(); int pos = 0;/* w ww .ja va2s.c o m*/ reader.mark(LOOKAHEAD); while (true) { int value = reader.read(); // Check to see if we hit the end of the stream. if (value == -1) { throw new IOException("Encounter end of stream before start of XML."); } else if (value == c[pos]) { pos++; } else { if (pos > 0) { pos = 0; } reader.mark(LOOKAHEAD); } if (pos == c.length) { // We found the character set we were looking for. reader.reset(); break; } } return reader; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.IOHelper.java
/** * Lists all xml files and throw an IOException if no XML files were found * * @param inputDir input dir/*from ww w. j av a 2 s . c om*/ * @return list of xml files * @throws IOException exception */ public static List<File> listXmlFiles(File inputDir) throws IOException { ArrayList<File> files = new ArrayList<>(FileUtils.listFiles(inputDir, new String[] { "xml" }, false)); if (files.isEmpty()) { throw new IOException("No xml files found in " + inputDir); } return files; }
From source file:com.opensearchserver.affinities.AffinityList.java
public static void load(File directory) throws IOException { if (INSTANCE != null) throw new IOException("Already loaded"); INSTANCE = new AffinityList(directory); }
From source file:Main.java
public static void save(String filename, Node node) throws IOException { PrintStream out = null;//from w w w . j a v a2 s. c o m try { out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8"); print(out, node); } catch (Exception ex) { throw new IOException(ex.getLocalizedMessage()); } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } }
From source file:com.google.jenkins.plugins.credentials.oauth.KeyUtils.java
/** * Creates a file with the given prefix/suffix in a standard Google auth * directory, and sets the permissions of the file to owner-only read/write. * * @throws IOException if filesystem interaction fails. *///w w w .j av a 2 s .c o m public static File createKeyFile(String prefix, String suffix) throws IOException { File keyFolder = new File(Jenkins.getInstance().getRootDir(), "gauth"); if (keyFolder.exists() || keyFolder.mkdirs()) { File result = File.createTempFile(prefix, suffix, keyFolder); if (result == null) { throw new IOException("Failed to create key file"); } updatePermissions(result); return result; } else { throw new IOException("Failed to create key folder"); } }
From source file:com.atlassian.jira.rest.client.internal.json.ResourceUtil.java
public static String getStringFromResource(String resourcePath) { final String s; try {//from w w w.j ava2s .c om final InputStream is = ResourceUtil.class.getResourceAsStream(resourcePath); if (is == null) { throw new IOException("Cannot open resource [" + resourcePath + "]"); } s = IOUtils.toString(is); } catch (IOException e) { throw new RuntimeException(e); } return s; }
From source file:Main.java
public static void blockUntilConnected(final SocketChannel channel, long timeout) throws IOException { ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, timeout, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { public Boolean call() { while (!channel.isConnected()) { try { Thread.sleep(300); } catch (InterruptedException e) { }/*from www . j a v a2 s. com*/ } return true; } }); executor.execute(future); try { future.get(timeout, TimeUnit.MILLISECONDS); } catch (Exception e) { channel.close(); throw new IOException(e); } }
From source file:Main.java
public static void copyCompletely(URI input, URI output) throws IOException { try {//from w w w . j a v a2s.c o m InputStream in = null; try { File f = new File(input); if (f.exists()) in = new FileInputStream(f); } catch (Exception notAFile) { } File out = new File(output); File dir = out.getParentFile(); dir.mkdirs(); if (in == null) in = input.toURL().openStream(); copyCompletely(in, new FileOutputStream(out)); } catch (IllegalArgumentException e) { throw new IOException("Cannot copy to " + output); } }