List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:PNGDecoder.java
public static BufferedImage decode(InputStream in) throws IOException { DataInputStream dataIn = new DataInputStream(in); readSignature(dataIn);// w w w. java 2s. co m PNGData chunks = readChunks(dataIn); long widthLong = chunks.getWidth(); long heightLong = chunks.getHeight(); if (widthLong > Integer.MAX_VALUE || heightLong > Integer.MAX_VALUE) throw new IOException("That image is too wide or tall."); int width = (int) widthLong; int height = (int) heightLong; ColorModel cm = chunks.getColorModel(); WritableRaster raster = chunks.getRaster(); BufferedImage image = new BufferedImage(cm, raster, false, null); return image; }
From source file:Main.java
public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); }/*from w w w .j av a2s . com*/ if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { forceDelete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) throw exception; }
From source file:com.symbian.driver.core.controller.utils.ControllerUtils.java
/** * Returns the key file.//from w w w . j a v a2 s . c om * * @return The file location of the SIS file key. * @throws IOException If the key has an I/O problem. */ public static final File getKey() throws IOException { if (sKey == null) { String lKey = null; try { lKey = TDConfig.getInstance().getPreference(TDConfig.KEY); } catch (ParseException lParseException) { LOGGER.log(Level.WARNING, "Could not get the custom Key Location.", lParseException); } if (lKey != null && new File(lKey).isFile()) { sKey = new File(lKey); return sKey; } if ((sKey = JarUtils.extractResource(ControllerUtils.class, "/resource/testdriver.key")) == null) { throw new IOException("Could not extract Key."); } try { TDConfig.getInstance().setPreference(TDConfig.KEY, sKey.getAbsolutePath()); } catch (ParseException e) { // Auto-generated catch block } } return sKey; }
From source file:org.transdroid.daemon.util.FakeSocketFactory.java
private static SSLContext createEasySSLContext(String certKey) throws IOException { try {/*from ww w . j av a 2 s . co m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new FakeTrustManager(certKey) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:me.prokopyl.commandtools.migration.UUIDFetcher.java
static public Map<String, UUID> fetch(List<String> names) throws IOException { Map<String, UUID> uuidMap = new HashMap<String, UUID>(); HttpURLConnection connection = createConnection(); writeBody(connection, names);/*from w w w . java2 s .c o m*/ JSONArray array; try { array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); } catch (ParseException ex) { throw new IOException("Invalid response from server, unable to parse received JSON : " + ex.toString()); } for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); uuidMap.put(name, fromMojangUUID(id)); } return uuidMap; }
From source file:com.google.resting.rest.CustomSSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/* www. j av a 2s. c om*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new CustomX509TrustManager() }, new java.security.SecureRandom()); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.xxg.jdeploy.util.FileUtil.java
/** * Writes a file from a string with a specified encoding. * * @param path/*www .ja v a 2 s.co m*/ * @param name * @param encoding * @param s * @throws IOException */ public static void writeString(String path, String name, String encoding, String s) throws IOException { String fileName = getPatchedFileName(path, name); if (UtilValidate.isEmpty(fileName)) { throw new IOException("Cannot obtain buffered writer for an empty filename!"); } try { FileUtils.writeStringToFile(new File(fileName), s, encoding); } catch (IOException e) { throw e; } }
From source file:Main.java
public static X509Certificate[] getSortedPath(X509Certificate[] inpath) throws IOException { try {//from w w w.j av a 2 s.c o m // Build/check path int n = 0; int[] idx = new int[inpath.length]; int[] jidx = new int[inpath.length]; boolean[] done = new boolean[inpath.length]; for (int i = 0; i < inpath.length; i++) { X500Principal p = inpath[i].getIssuerX500Principal(); idx[i] = -1; for (int j = 0; j < inpath.length; j++) { if (j == i || done[j]) continue; if (p.equals(inpath[j].getSubjectX500Principal())) // J is certifying I { n++; idx[i] = j; jidx[j] = i; done[j] = true; inpath[i].verify(inpath[j].getPublicKey()); break; } } } if (n != (inpath.length - 1)) { throw new IOException("X509Certificate elements contain multiple or broken cert paths"); } // Path OK, now sort it X509Certificate[] certpath = new X509Certificate[inpath.length]; for (int i = 0; i < inpath.length; i++) { if (idx[i] < 0) // Must be the highest { certpath[n] = inpath[i]; while (--n >= 0) { certpath[n] = inpath[i = jidx[i]]; } break; } } return certpath; } catch (GeneralSecurityException gse) { throw new IOException(gse); } }
From source file:com.qwazr.utils.process.ProcessUtils.java
public static Integer forceKill(Number pid) throws IOException, InterruptedException { if (pid == null) return null; final String commandLine; if (SystemUtils.IS_OS_UNIX) commandLine = "kill -9 " + pid; else if (SystemUtils.IS_OS_WINDOWS) commandLine = "taskkill /F /PID " + pid; else/*from w w w . jav a 2 s . c o m*/ throw new IOException(NOT_SUPPORTED_ERROR); return run(commandLine); }
From source file:com.farru.android.network.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/*ww w . j av a 2 s . c o m*/ SSLContext context = SSLContext.getInstance("SSL"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }