List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:com.genericworkflownodes.knime.custom.ZipUtilsTest.java
public static File createTempDirectory() throws IOException { final File temp; temp = File.createTempFile("temp", Long.toString(System.nanoTime())); if (!(temp.delete())) { throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); }//from ww w . jav a2s . c o m if (!(temp.mkdir())) { throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); } return (temp); }
From source file:Main.java
/** * This will parse an InputSource and create a DOM document. * * @param is The stream to get the XML from. * @return The DOM document.//from w w w.j av a2 s .com * @throws IOException It there is an error creating the dom. */ public static Document parse(InputSource is) throws IOException { try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.parse(is); } catch (Exception e) { IOException thrown = new IOException(e.getMessage()); throw thrown; } }
From source file:Main.java
public static String readXmlAsString(final File input) throws IOException { String xmlString = ""; if (input == null) { throw new IOException("The input stream object is null."); }/* w ww . j av a 2 s .co m*/ final FileInputStream fileInputStream = new FileInputStream(input); final InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); final BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line = bufferedReader.readLine(); while (line != null) { xmlString += line + "\n"; line = bufferedReader.readLine(); } fileInputStream.close(); fileInputStream.close(); bufferedReader.close(); return xmlString; }
From source file:com.qwazr.utils.process.ProcessUtils.java
public static Integer kill(Number pid) throws IOException, InterruptedException { if (pid == null) return null; final String commandLine; if (SystemUtils.IS_OS_UNIX) commandLine = "kill " + pid; else if (SystemUtils.IS_OS_WINDOWS) commandLine = "taskkill /PID " + pid; else/*from w w w.j av a2s. co m*/ throw new IOException(NOT_SUPPORTED_ERROR); return run(commandLine); }
From source file:FileUtil.java
public static void copyFile(String from, String to, Boolean overwrite) { try {/*from w ww . j a v a 2s. co m*/ File fromFile = new File(from); File toFile = new File(to); if (!fromFile.exists()) { throw new IOException("File not found: " + from); } if (!fromFile.isFile()) { throw new IOException("Can't copy directories: " + from); } if (!fromFile.canRead()) { throw new IOException("Can't read file: " + from); } if (toFile.isDirectory()) { toFile = new File(toFile, fromFile.getName()); } if (toFile.exists() && !overwrite) { throw new IOException("File already exists."); } else { String parent = toFile.getParent(); if (parent == null) { parent = System.getProperty("user.dir"); } File dir = new File(parent); if (!dir.exists()) { throw new IOException("Destination directory does not exist: " + parent); } if (dir.isFile()) { throw new IOException("Destination is not a valid directory: " + parent); } if (!dir.canWrite()) { throw new IOException("Can't write on destination: " + parent); } } FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(fromFile); fos = new FileOutputStream(toFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } finally { if (from != null) { try { fis.close(); } catch (IOException e) { System.out.println(e); } } if (to != null) { try { fos.close(); } catch (IOException e) { System.out.println(e); } } } } catch (Exception e) { System.out.println("Problems when copying file."); } }
From source file:eu.freme.eservices.epublishing.Unzipper.java
public static void unzip(ZipInputStream zis, File outputFolder) throws IOException { //create output directory is not exists if (!outputFolder.exists() && !outputFolder.mkdirs()) { throw new IOException("Cannot create directory " + outputFolder); }//from www. ja v a 2s. co m //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder, fileName); logger.debug("file unzip : " + newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder File parentDir = newFile.getParentFile(); if (!parentDir.exists() && !parentDir.mkdirs()) { throw new IOException("Cannot create directory " + newFile.getParent()); } if (ze.isDirectory()) { newFile.mkdirs(); } else { try (FileOutputStream fos = new FileOutputStream(newFile)) { IOUtils.copyLarge(zis, fos); } } ze = zis.getNextEntry(); } zis.closeEntry(); }
From source file:com.bottlerocketstudios.groundcontrolsample.core.controller.ProductApi.java
public static JSONObject downloadJson(OkHttpClient okHttpClient, Request request) throws IOException, JSONException { Response response = okHttpClient.newCall(request).execute(); if (response.isSuccessful()) { return new JSONObject(response.body().string()); } else {//from w w w .j a v a 2s . c om throw new IOException("Server did not respond with success"); } }
From source file:com.anjlab.tapestry5.services.ConfigHelper.java
public static ConfigHelper fromClasspathResource(String resourceName) throws IOException { logger.info("Reading config from classpath: {}", resourceName); InputStream input = ConfigHelper.class.getClassLoader().getResourceAsStream(resourceName); if (input == null) { throw new IOException("Classpath resource not found: " + resourceName); }/* w w w . j av a 2 s . c om*/ return new ConfigHelper(new AutoCloseInputStream(input)); }
From source file:Main.java
public static void save(String filename, Document document) throws IOException { PrintStream out = null;/*from w w w. j av a 2s . c om*/ try { out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8"); // traceNode(document, ""); print(out, document); } catch (Exception ex) { throw new IOException(ex.getLocalizedMessage()); } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } }
From source file:com.indexoutofbounds.util.ClassPathInputStreamUtils.java
/** * Creates an InputStream from the path which can be either something on * the file system, a remote system, or a classpath entry. * @param path// w ww .j av a 2 s .c om * @return * @throws Exception */ public final static InputStream getInputStream(final String path) throws IOException { if (StringUtils.isEmpty(path)) { throw new IOException("Unable to locate empty config file parameter"); } final URL url = locateURL(path); if (url == null) { throw new IOException("Unable to locate config file: " + path); } try { return new BufferedInputStream(url.openStream()); } catch (IOException e) { throw new IOException("Unable to open config file: " + path + ", " + e.getLocalizedMessage()); } }