List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:uk.ac.ebi.atlas.utils.HttpRequest.java
public static InputStream httpPost(org.apache.http.client.HttpClient httpClient, String url, List<? extends NameValuePair> params) throws IOException { HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = httpClient.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { return response.getEntity().getContent(); }//from ww w. ja v a 2s .co m throw new IOException( "Server returned invalid response: [status_code = " + statusCode + "; url = " + url + "]"); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.createdebate.CorpusPreparator.java
/** * Extracts all debates from raw HTML files in inFolder and stores them into outFolder * as serialized {@link Debate} objects (see {@link DebateSerializer}. * * @param inFolder in folder/*from w w w .jav a2 s .c om*/ * @param outFolder out folder (must exist) * @param debateParser debate parser implementation * @throws IOException exception */ public static void extractAllDebates(File inFolder, File outFolder, DebateParser debateParser) throws IOException { File[] files = inFolder.listFiles(); if (files == null) { throw new IOException("No such dir: " + inFolder); } for (File f : files) { InputStream inputStream = new FileInputStream(f); try { Debate debate = debateParser.parseDebate(inputStream); // we ignore empty debates (without arguments) if (debate != null && !debate.getArgumentList().isEmpty()) { // serialize to xml String xml = DebateSerializer.serializeToXML(debate); // same name with .xml File outputFile = new File(outFolder, f.getName() + ".xml"); FileUtils.writeStringToFile(outputFile, xml, "utf-8"); System.out.println("Saved to " + outputFile.getAbsolutePath()); // ensure we can read it again DebateSerializer.deserializeFromXML(FileUtils.readFileToString(outputFile)); } } catch (IOException ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); } } }
From source file:org.openhab.binding.rwesmarthome.internal.communicator.util.EasySSLSocketFactory.java
/** * Creates an SSL context./*from www . j a v a2 s . c o m*/ * * @return * @throws IOException */ private static SSLContext createEasySSLContext() throws IOException { try { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.twinsoft.convertigo.engine.util.FileUtils.java
public static void mergeDirectories(File srcDir, File destDir, boolean preserveFileDate) throws IOException { File[] files = srcDir.listFiles(); if (files == null) { // null if security restricted throw new IOException("Failed to list contents of " + srcDir); }/*from www.j a va 2 s . c o m*/ if (destDir.exists()) { if (destDir.isDirectory() == false) { throw new IOException("Destination '" + destDir + "' exists but is not a directory"); } } else { if (destDir.mkdirs() == false) { throw new IOException("Destination '" + destDir + "' directory cannot be created"); } String message = "> Directory '" + destDir + "' created"; if (Engine.logEngine != null) { Engine.logEngine.info(message); } else { System.out.println(message); } } if (destDir.canWrite() == false) { throw new IOException("Destination '" + destDir + "' cannot be written to"); } for (File file : files) { File copiedFile = new File(destDir, file.getName()); if (file.isDirectory()) { mergeDirectories(file, copiedFile, preserveFileDate); } else { if (!copiedFile.exists()) { FileUtils.copyFile(file, copiedFile, preserveFileDate); String message = "+ File '" + file + "' copied from " + srcDir; if (Engine.logEngine != null) { Engine.logEngine.info(message); } else { System.out.println(message); } } } } }
From source file:ResourcesUtils.java
/** * Returns the URL of the resource on the classpath * /*from w w w . ja v a 2s . c o m*/ * @param resource * The resource to find * @throws IOException * If the resource cannot be found or read * @return The resource */ public static URL getResourceURL(String resource) throws IOException { URL url = null; ClassLoader loader = ResourcesUtils.class.getClassLoader(); if (loader != null) { url = loader.getResource(resource); } if (url == null) { url = ClassLoader.getSystemResource(resource); } if (url == null) { throw new IOException("Could not find resource " + resource); } return url; }
From source file:com.github.dockerjava.test.serdes.JSONTestHelper.java
/** * Reads JSON String from the specified resource * //from w w w . j a va2s. co m * @param resource * JSON File * @return JSON String * @throws IOException * JSON Conversion error */ public static String readString(JSONResourceRef resource) throws IOException { try (InputStream istream = resource.getResourceClass().getResourceAsStream(resource.getFileName())) { if (istream == null) { throw new IOException("Cannot retrieve resource " + resource.getFileName()); } return IOUtils.toString(istream, "UTF-8"); } }
From source file:com.qwazr.scripts.ScriptManager.java
public synchronized static Class<? extends ScriptServiceInterface> load(ExecutorService executorService, File directory) throws IOException { if (INSTANCE != null) throw new IOException("Already loaded"); try {/*from ww w . ja v a2s .c o m*/ INSTANCE = new ScriptManager(executorService, directory); return ClusterManager.INSTANCE.isCluster() ? ScriptClusterServiceImpl.class : ScriptSingleServiceImpl.class; } catch (URISyntaxException e) { throw new IOException(e); } }
From source file:com.compomics.pride_asa_pipeline.core.repository.factory.FileParserFactory.java
public static FileParser getFileParser(File inputFile) throws IOException { currentInputFile = inputFile;/*from w ww .j av a2s . c o m*/ FileParser parser = null; String extension = FilenameUtils.getExtension(inputFile.getAbsolutePath()).toLowerCase(); //TODO if extension =.gz ---> unzip ---> new extension if (extension.equalsIgnoreCase("zip")) { } else if (extension.equalsIgnoreCase("gz")) { } else if (extension.equalsIgnoreCase("rar")) { } else if (extension.equalsIgnoreCase("tar")) { } switch (extension.toLowerCase()) { case "mzid": LOGGER.info("Detected mzml file extension."); parser = new MzIdentMlParser(); break; case "xml": LOGGER.info("Detected xml file extension."); parser = new PrideXmlParser(); break; default: throw new IOException("Unsupported filetype for parameter-extraction : ." + extension); } return parser; }
From source file:melnorme.utilbox.misc.FileUtil.java
/** Read all bytes of the given file. * @return the bytes that where read in a {@link java.io.ByteArrayOutputStream}. */ public static IByteSequence readBytesFromFile(File file) throws IOException, FileNotFoundException { long fileLength = file.length(); /*/*from w ww . j a va 2 s. co m*/ * You cannot create an array using a long type. It needs to be an * int type. Before converting to an int type, check to ensure * that file is not larger than Integer.MAX_VALUE. */ if (fileLength > Integer.MAX_VALUE) throw new IOException("File is too large, size is bigger than " + Integer.MAX_VALUE); return StreamUtil.readAllBytesFromStream(new FileInputStream(file), (int) fileLength); }
From source file:it.restrung.rest.misc.FakeSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/* ww w . j av a 2 s. c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new FakeTrustManager() }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }