List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:com.Kuesty.services.JSONRequest.java
public static void execute(String uri, JSONRequestTaskHandler rsh) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response;// w w w. ja v a 2s . co m String responseString = null; try { response = httpclient.execute(new HttpGet(uri)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else { //Closes the connection. response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { rsh.onError(e.getMessage()); } catch (IOException e) { rsh.onError(e.getMessage()); } try { JSONObject response1 = new JSONObject(responseString); rsh.onSuccess(response1); } catch (JSONException e) { rsh.onError(e.getMessage()); } }
From source file:org.jboss.arquillian.spring.integration.inject.model.CustomExceptionApplicationContextClass.java
/** * A utility method for instantiating the application context. * * @return the spring application context *//*from w ww . j av a 2s . c o m*/ @SpringContextConfiguration public static ApplicationContext contextConfiguration() throws IOException { throw new IOException("Test exception"); }
From source file:com.spstudio.common.image.ImageUtils.java
public static String cutImage(String sourcePath, String targetPath, int x, int y, int width, int height) throws IOException { File imageFile = new File(sourcePath); if (!imageFile.exists()) { throw new IOException("Not found the images:" + sourcePath); }/*from w w w . ja v a2 s . com*/ if (targetPath == null || targetPath.isEmpty()) { targetPath = sourcePath; } String format = sourcePath.substring(sourcePath.lastIndexOf(".") + 1, sourcePath.length()); BufferedImage image = ImageIO.read(imageFile); image = image.getSubimage(x, y, width, height); ImageIO.write(image, format, new File(targetPath)); return targetPath; }
From source file:org.psidnell.omnifocus.ApplicationContextFactory.java
public static Properties getConfigProperties() throws IOException { try (InputStream in = ApplicationContextFactory.class.getResourceAsStream(CONFIG_PROPERTIES)) { if (in == null) { throw new IOException("config not found"); }//from ww w. j av a2 s . c om Properties config = new Properties(); config.load(in); return config; } }
From source file:com.eatnumber1.util.io.IOUtils.java
public static void read(@NotNull ReadableByteChannel channel, @NotNull ByteBuffer dst, int expected) throws IOException { if (channel.read(dst) != expected) throw new IOException("Did not read expected amount of data"); }
From source file:Main.java
public static void readTillEnd(InputStream in, byte[] buf, boolean eofOK) throws IOException { int toRead = buf.length; int numRead = 0; while (numRead < toRead) { int nread = in.read(buf, numRead, toRead - numRead); if (nread < 0) { if (eofOK) { // EOF hit, fill with zeros Arrays.fill(buf, numRead, toRead, (byte) 0); numRead = toRead;/*from ww w. jav a2 s .c o m*/ } else { // EOF hit, throw. throw new IOException("Premature EOF"); } } else { numRead += nread; } } }
From source file:Main.java
public static void deleteFromInternalStorage(Context context, final String contains) throws IOException { File file = context.getFilesDir(); FilenameFilter filter = new FilenameFilter() { @Override/*from w ww. j a v a 2s .c o m*/ public boolean accept(File dir, String filename) { return filename.contains(contains); } }; File[] files = file.listFiles(filter); if (files != null) { for (File f : files) { //noinspection ResultOfMethodCallIgnored if (!f.delete()) { throw new IOException("Error while deleting files"); } } } }
From source file:Main.java
public static String readXmlAsString(File input) throws IOException { String xmlString = ""; if (input == null) { throw new IOException("The input stream object is null."); }//from w ww .j a v a2s .c o m FileInputStream fileInputStream = new FileInputStream(input); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); 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:Main.java
public static boolean symlink(File inFile, File outFile) { int exitCode = -1; try {/*from w w w . j a va2s. c o m*/ Process sh = Runtime.getRuntime().exec("sh"); OutputStream out = sh.getOutputStream(); String command = "/system/bin/ln -s " + inFile + " " + outFile + "\nexit\n"; out.write(command.getBytes("ASCII")); final char buf[] = new char[40]; InputStreamReader reader = new InputStreamReader(sh.getInputStream()); while (reader.read(buf) != -1) throw new IOException("stdout: " + new String(buf)); reader = new InputStreamReader(sh.getErrorStream()); while (reader.read(buf) != -1) throw new IOException("stderr: " + new String(buf)); exitCode = sh.waitFor(); } catch (IOException e) { e.printStackTrace(); return false; } catch (InterruptedException e) { e.printStackTrace(); return false; } return exitCode == 0; }
From source file:Main.java
private static byte[] uncompressBytesInflateDeflate(byte[] inBytes) throws IOException { Inflater inflater = new Inflater(); inflater.setInput(inBytes);/*from w ww. ja va 2 s . c om*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(inBytes.length); byte[] buffer = new byte[1024 * 8]; while (!inflater.finished()) { int count; try { count = inflater.inflate(buffer); } catch (DataFormatException e) { throw new IOException(e); } bos.write(buffer, 0, count); } byte[] output = bos.toByteArray(); return output; }