List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:com.sshtools.daemon.platform.NativeProcessProvider.java
/** * * * @return//from w w w .ja v a2 s.c o m * * @throws IOException */ public static NativeProcessProvider newInstance() throws IOException { try { return (NativeProcessProvider) provider.newInstance(); } catch (Exception e) { throw new IOException("The process provider failed to create a new instance: " + e.getMessage()); } }
From source file:com.mmone.gpdati.allotment.reader.AllotmentFileReader.java
private void loadData() throws IOException { try {/*from w w w . jav a2 s . co m*/ Logger.getLogger(AllotmentFileReader.class.getName()).log(Level.INFO, "**** target filename " + fileName); File file = new File(fileName); if (file.exists()) { Logger.getLogger(AllotmentFileReader.class.getName()).log(Level.INFO, "**** file exist " + fileName); lines = FileUtils.readLines(file, "UTF-8"); } else { Logger.getLogger(AllotmentFileReader.class.getName()).log(Level.INFO, "**** file not found " + fileName); throw new IOException("File not found " + fileName); } } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.yahoo.parsec.gradle.generators.ParsecGeneratorUtil.java
/** * Get Intersect PackageName, leave as non-static will make other package mock this method easier. * * @throws IOException IOException//from ww w . java 2 s .c o m * @param packageNames package names * @return intersect package name */ public String getIntersectPackageName(ArrayList<String> packageNames) throws IOException { if (packageNames == null || packageNames.size() == 0) { throw new IOException("packageNames is null or empty"); } // choose first package name as baseline of package names int packageCount = packageNames.size(); String firstPackageName = packageNames.get(0); String[] parts = firstPackageName.split("\\."); // if firstPackageName = "com.example" // the accumlateParts will be composed of [ "com", "com.example" ] List<String> accumulateParts = new ArrayList<>(); String currPart = ""; for (String part : parts) { currPart += currPart.isEmpty() ? part : "." + part; accumulateParts.add(currPart); } // try to find out the intersect package name by reverse order of accumulate parts // the order of match pattern would be something like "com.example", "com" for (int i = accumulateParts.size() - 1; i >= 0; i--) { String part = accumulateParts.get(i); int matchCount = 0; for (String packageName : packageNames) { // match com.example or com. String pattern = "^" + part + "(\\..+|$)"; if (packageName.matches(pattern)) { // make sure all package names have at least one intersect part matchCount++; if (matchCount == packageCount) { return part; } } } } throw new IOException("no intersect part found from packages"); }
From source file:com.adaptris.core.util.MimeHelper.java
/** * Convenience method to create a {@link ByteArrayIterator} on a message allowing you to iterate a mime-payload. * //from w w w.j a v a2s .c o m */ public static ByteArrayIterator createByteArrayIterator(AdaptrisMessage msg) throws IOException, MessagingException { ByteArrayIterator result = null; try (InputStream in = msg.getInputStream()) { result = new ByteArrayIterator(in); } catch (Exception e) { String mimeBoundary = getBoundary(msg); result = createByteArrayIterator(mimeFaker(msg, mimeBoundary)); } if (result == null) { throw new IOException("Could not parse " + msg.getUniqueId() + " into a standard MIME Multipart"); } return result; }
From source file:alluxio.util.network.HttpUtils.java
/** * Uses the post method to send a url with arguments by http, this method can call RESTful Api. * * @param url the http url/*from w w w . j a v a 2 s . co m*/ * @param timeout milliseconds to wait for the server to respond before giving up * @param processInputStream the response body stream processor */ public static void post(String url, Integer timeout, IProcessInputStream processInputStream) throws IOException { Preconditions.checkNotNull(timeout, "timeout"); Preconditions.checkNotNull(processInputStream, "processInputStream"); PostMethod postMethod = new PostMethod(url); try { HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout); int statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream inputStream = postMethod.getResponseBodyAsStream(); processInputStream.process(inputStream); } else { throw new IOException("Failed to perform POST request. Status code: " + statusCode); } } finally { postMethod.releaseConnection(); } }
From source file:com.elega9t.commons.geo.impl.HostIpDotInfoGeoLocationProvider.java
@Override public GeoLocationInfo lookup(String ip) throws IOException { URL url = new URL("http://api.hostip.info/get_json.php?ip=" + URLEncoder.encode(ip, "UTF-8")); URLConnection connection = url.openConnection(); connection.connect();// w ww. j a va 2 s . c o m InputStream inputStream = connection.getInputStream(); String json = IOUtilities.toString(inputStream); inputStream.close(); try { JSONObject object = new JSONObject(json); return new GeoLocationInfo(object.getString("ip"), object.getString("country_name"), object.getString("country_code"), object.getString("city")); } catch (JSONException e) { throw new IOException(e); } }
From source file:core.RESTCalls.RESTPost.java
public static String httpPost(String urlStr, String[] paramName, String[] paramVal) throws Exception { URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true);//from www . ja v a2s .co m conn.setDoInput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream out = conn.getOutputStream(); Writer writer = new OutputStreamWriter(out, "UTF-8"); for (int i = 0; i < paramName.length; i++) { writer.write(paramName[i]); writer.write("="); writer.write(URLEncoder.encode(paramVal[i], "UTF-8")); writer.write("&"); } writer.close(); out.close(); if (conn.getResponseCode() != 200) throw new IOException(conn.getResponseMessage()); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) sb.append(line + "\n"); rd.close(); conn.disconnect(); return sb.toString(); }
From source file:de.teamgrit.grit.report.PdfConcatenator.java
/** * Concatinates pdfs generated {@link TexGenerator}. * * @param folderWithPdfs/*from w ww. j a va2s . c o m*/ * the folder with pdfs * @param outPath * the out path * @param exerciseName * the context * @param studentsWithoutSubmissions * list of students who did not submit any solution * @return the path to the created PDF * @throws IOException * Signals that an I/O exception has occurred. */ protected static Path concatPDFS(Path folderWithPdfs, Path outPath, String exerciseName, List<Student> studentsWithoutSubmissions) throws IOException { if ((folderWithPdfs == null) || !Files.isDirectory(folderWithPdfs)) { throw new IOException("The Path doesn't point to a Folder"); } File file = new File(outPath.toFile(), "report.tex"); if (Files.exists(file.toPath(), LinkOption.NOFOLLOW_LINKS)) { Files.delete(file.toPath()); } file.createNewFile(); writePreamble(file, exerciseName); writeMissingStudents(file, studentsWithoutSubmissions); writeFiles(file, folderWithPdfs); writeClosing(file); PdfCreator.createPdfFromPath(file.toPath(), outPath); return file.toPath(); }
From source file:eu.swiec.bearballin.common.io.FileIO.java
private static String[] getLoginPassFromCSV(Reader in) throws IOException { BufferedReader bufRdr;/*from ww w . j a v a 2 s. c om*/ bufRdr = new BufferedReader(in); String line = null; String[] loginPassPair = new String[7]; int i = 0; while ((line = bufRdr.readLine()) != null) { loginPassPair[i] = line; i++; } if (i < 1) throw new IOException( "Invalid login/password file structure. First line must conatin login, second line - password"); bufRdr.close(); return loginPassPair; }
From source file:edu.usf.cutr.obascs.io.FileUtil.java
public static Map<String, String> readAgencyInformantions(String path) throws IOException { Map<String, String> agencyMap = new HashMap<String, String>(); BufferedReader br = new BufferedReader(new FileReader(path)); try {/*w w w . j a v a 2 s . co m*/ String line = br.readLine(); while (line != null) { if (StringUtils.isNotBlank(line) && line.contains(GeneralConstants.AGENCY_MAP_IDENTIFIER) == false) { try { String[] split = line.split(StringConstants.COMMA); String agency = null; if (StringUtils.isNotBlank(split[0])) { agency = split[0]; } else { agency = split[1]; } agencyMap.put(agency, split[2]); } catch (Exception e) { throw new IOException("Wrong line format. Line should be comma seperated."); } } line = br.readLine(); } } finally { br.close(); } return agencyMap; }