List of usage examples for java.io IOException IOException
public IOException(Throwable cause)
From source file:org.bobarctor.Rm3Wifi.utils.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {//from w w w . j av a2s. com 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.marklogic.client.example.handle.JacksonHandleExample.java
public static void run(ExampleProperties props) throws IOException { System.out.println("example: " + JacksonHandleExample.class.getName()); String filename = "flipper.json"; // create the client DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, props.writerUser, props.writerPassword, props.authType); // create a manager for JSON documents JSONDocumentManager docMgr = client.newJSONDocumentManager(); // read the example file InputStream docStream = Util.openStream("data" + File.separator + filename); if (docStream == null) throw new IOException("Could not read document example"); // create an identifier for the document String docId = "/example/" + filename; // create a handle for the document JacksonHandle writeHandle = new JacksonHandle(); // parse the example file into a Jackson JSON structure JsonNode writeDocument = writeHandle.getMapper().readValue(new InputStreamReader(docStream, "UTF-8"), JsonNode.class); writeHandle.set(writeDocument);/*from w w w .j a v a2s . c o m*/ // write the document docMgr.write(docId, writeHandle); // create a handle to receive the document content JacksonHandle readHandle = new JacksonHandle(); // read the document content docMgr.read(docId, readHandle); // access the document content JsonNode readDocument = readHandle.get(); String aRootField = null; Iterator<String> iterator = readDocument.fieldNames(); while (iterator.hasNext()) { aRootField = iterator.next(); } // delete the document docMgr.delete(docId); System.out.println("Wrote and read /example/" + filename + " content with a root field name of " + aRootField + " using Jackson"); // release the client client.release(); }
From source file:ca.uvic.cs.tagsea.wizards.TagNetworkSender.java
public static synchronized void send(String xml, IProgressMonitor sendMonitor, int id) throws InvocationTargetException { sendMonitor.beginTask("Uploading Tags", 100); sendMonitor.subTask("Saving Temporary file..."); File location = TagSEAPlugin.getDefault().getStateLocation().toFile(); File temp = new File(location, "tagsea.temp.file.txt"); if (temp.exists()) { String message = "Unable to send tags. Unable to create temporary file."; IOException ex = new IOException(message); throw (new InvocationTargetException(ex, message)); }/* w w w . j a va 2 s . co m*/ try { FileWriter writer = new FileWriter(temp); writer.write(xml); writer.flush(); writer.close(); } catch (IOException e) { throw new InvocationTargetException(e); } sendMonitor.worked(5); sendMonitor.subTask("Uploading Tags..."); String uploadScript = "http://stgild.cs.uvic.ca/cgi-bin/tagSEAUpload.cgi"; PostMethod post = new PostMethod(uploadScript); String fileName = getToday() + ".txt"; try { Part[] parts = { new StringPart("KIND", "tag"), new FilePart("MYLAR" + id, fileName, temp) }; post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); int status = client.executeMethod(post); String resp = getData(post.getResponseBodyAsStream()); if (status != 200) { IOException ex = new IOException(resp); throw (ex); } } catch (IOException e) { throw new InvocationTargetException(e, e.getLocalizedMessage()); } finally { sendMonitor.worked(90); sendMonitor.subTask("Deleting Temporary File"); temp.delete(); sendMonitor.done(); } }
From source file:ca.nines.ise.util.TextReplacementTable.java
public static TextReplacementTable defaultTextReplacementTable() throws IOException { String loc = "/data/text-replacements.csv"; InputStream in = TextReplacementTable.class.getResourceAsStream(loc); if (in == null) { throw new IOException("Cannot find " + loc + " as a resource."); }//from www . ja va 2 s . com return builder().from(in).build(); }
From source file:com.splout.db.hadoop.SchemaSampler.java
public static Schema sample(Configuration conf, Path input, InputFormat<ITuple, NullWritable> inputFormat) throws IOException, InterruptedException { Schema schema = null;//from w ww . j a v a 2s. c o m // sample schema from input path given the provided InputFormat @SuppressWarnings("deprecation") Job job = new Job(conf); FileInputFormat.setInputPaths(job, input); // get first inputSplit List<InputSplit> inputSplits = inputFormat.getSplits(job); if (inputSplits == null || inputSplits.size() == 0) { throw new IOException( "Given input format doesn't produce any input split. Can't sample first record. PATH: " + input); } InputSplit inputSplit = inputSplits.get(0); TaskAttemptID attemptId = new TaskAttemptID(new TaskID(), 1); TaskAttemptContext attemptContext; try { attemptContext = TaskAttemptContextFactory.get(conf, attemptId); } catch (Exception e) { throw new IOException(e); } RecordReader<ITuple, NullWritable> rReader = inputFormat.createRecordReader(inputSplit, attemptContext); rReader.initialize(inputSplit, attemptContext); if (!rReader.nextKeyValue()) { throw new IOException( "Can't read first record of first input split of the given path [" + input + "]."); } // finally get the sample schema schema = rReader.getCurrentKey().getSchema(); log.info("Sampled schema from [" + input + "] : " + schema); rReader.close(); return schema; }
From source file:ai.susi.json.JsonFile.java
/** * static JSON reader which is able to read a json file written by JsonFile * @param file/* www. j av a 2s. co m*/ * @return the json * @throws IOException */ public static JSONObject readJson(File file) throws IOException { if (file == null) throw new IOException("file must not be null"); JSONObject json = new JSONObject(true); JSONTokener tokener; tokener = new JSONTokener(new FileReader(file)); json.putAll(new JSONObject(tokener)); return json; }
From source file:com.qwazr.scheduler.SchedulerManager.java
public static synchronized Class<? extends SchedulerServiceInterface> load(TrackedDirectory etcTracker, int maxThreads) throws IOException { if (INSTANCE != null) throw new IOException("Already loaded"); try {/* www .j av a2 s.co m*/ INSTANCE = new SchedulerManager(etcTracker, maxThreads); etcTracker.register(INSTANCE); return SchedulerServiceImpl.class; } catch (ServerException | SchedulerException e) { throw new RuntimeException(e); } }
From source file:com.googlecode.fightinglayoutbugs.helpers.FileHelper.java
public static File createTempDir() throws IOException { final File baseDir = new File(System.getProperty("java.io.tmpdir")); if (!baseDir.isDirectory()) { throw new IOException("java.io.tmpdir (" + baseDir + ") is not a directory."); }//from ww w . jav a 2 s.co m final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); int i = 0; while (!stackTrace[i].getClassName().equals(FileHelper.class.getName())) { ++i; } while (stackTrace[i].getClassName().equals(FileHelper.class.getName())) { ++i; } String prefix = stackTrace[i].getClassName(); prefix = prefix.substring(prefix.lastIndexOf('.') + 1); File tempDir; boolean tempDirSuccessfullyCreated; do { final long randomLong = LazyInitRandom.nextLong(); final String dirName = prefix + (randomLong < 0 ? randomLong : "-" + randomLong); tempDir = new File(baseDir, dirName); tempDirSuccessfullyCreated = !tempDir.exists() && tempDir.mkdir(); } while (!tempDirSuccessfullyCreated); return tempDir; }
From source file:gaffer.utils.WritableToStringConverter.java
public static Writable deserialiseFromString(String serialised) throws IOException { // Convert the base64 string to a byte array byte[] b = Base64.decodeBase64(serialised); // Deserialise the writable from the byte array ByteArrayInputStream bais = new ByteArrayInputStream(b); DataInput in = new DataInputStream(bais); String className = Text.readString(in); try {/*from ww w. ja v a2s . c o m*/ Writable writable = (Writable) Class.forName(className).newInstance(); writable.readFields(in); return writable; } catch (InstantiationException e) { throw new IOException("Exception deserialising writable: " + e); } catch (IllegalAccessException e) { throw new IOException("Exception deserialising writable: " + e); } catch (ClassNotFoundException e) { throw new IOException("Exception deserialising writable: " + e); } catch (ClassCastException e) { throw new IOException("Exception deserialising writable: " + e); } }
From source file:com.splunk.shuttl.testutil.TUtilsFile.java
/** * @return a temporary, existing, empty file that will be deleted when the VM * terminates.//from w w w.jav a2 s . c o m * * @see TUtilsFile#createFilePath() */ public static File createFile() { File uniquelyNamedFile = getUniquelyNamedFileWithPrefix("test-file"); try { if (!uniquelyNamedFile.createNewFile()) throw new IOException("Could not create file: " + uniquelyNamedFile); FileUtils.forceDeleteOnExit(uniquelyNamedFile); } catch (IOException e) { TUtilsTestNG.failForException("Couldn't create a test file.", e); } return uniquelyNamedFile; }