List of usage examples for java.io UncheckedIOException UncheckedIOException
public UncheckedIOException(IOException cause)
From source file:edu.jhu.hlt.concrete.ingesters.bolt.BoltForumPostIngester.java
public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); if (args.length < 2) { LOGGER.info("Usage: {} {} {} {}", BoltForumPostIngester.class.getName(), "/path/to/output/folder", "/path/to/bolt/.xml/file", "<additional/xml/file/paths>"); System.exit(1);/*from w w w . j av a2 s. co m*/ } Path outPath = Paths.get(args[0]); Optional.ofNullable(outPath.getParent()).ifPresent(p -> { if (!Files.exists(p)) try { Files.createDirectories(p); } catch (IOException e) { throw new UncheckedIOException(e); } }); if (!Files.isDirectory(outPath)) { LOGGER.error("Output path must be a directory."); System.exit(1); } BoltForumPostIngester ing = new BoltForumPostIngester(); for (int i = 1; i < args.length; i++) { Path lp = Paths.get(args[i]); LOGGER.info("On path: {}", lp.toString()); try { Communication c = ing.fromCharacterBasedFile(lp); new WritableCommunication(c).writeToFile(outPath.resolve(c.getId() + ".comm"), true); } catch (IngestException | ConcreteException e) { LOGGER.error("Caught exception during ingest on file: " + args[i], e); } } }
From source file:com.joyent.manta.client.multipart.TestMultipartManager.java
@Override public void complete(TestMultipartUpload upload, Stream<? extends MantaMultipartUploadTuple> partsStream) throws IOException { Validate.notNull(upload, "Upload state object must not be null"); File objectContents = upload.getContents(); try (Stream<? extends MantaMultipartUploadTuple> sorted = partsStream.sorted(); FileOutputStream fout = new FileOutputStream(objectContents)) { sorted.forEach(tuple -> {// w w w . ja v a 2s . co m final int partNumber = tuple.getPartNumber(); File part = new File(upload.getPartsPath() + File.separator + partNumber); try (FileInputStream fin = new FileInputStream(part)) { IOUtils.copy(fin, fout); } catch (IOException e) { throw new UncheckedIOException(e); } }); } if (upload.getContentLength() != null) { Validate.isTrue(upload.getContentLength().equals(objectContents.length()), "Completed object's content length [%d] didn't equal expected length [%d]", objectContents.length(), upload.getContentLength()); } }
From source file:objective.taskboard.followup.FollowUpHelper.java
public static FollowUpData getFromFile() { Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create(); try (InputStream file = FollowUpHelper.class.getResourceAsStream("jiradata.json")) { return gson.fromJson(new InputStreamReader(file), FollowUpData.class); } catch (IOException e) { throw new UncheckedIOException(e); }//w w w.j a v a 2 s . c o m }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public static long countLines(Path path) { try (Stream<String> lines = Files.lines(path)) { return lines.count(); } catch (IOException e) { throw new UncheckedIOException(e); }//www .j a va 2 s. c o m }
From source file:no.imr.sea2data.stox.InstallerUtil.java
public static Boolean retrieveFromFTP(String ftpPath, String outFile, FTPFileFilter filter) { try {//from w w w .j av a 2 s . c o m FTPClient ftpClient = new FTPClient(); // pass directory path on server to connect if (ftpPath == null) { return false; } ftpPath = ftpPath.replace("ftp://", ""); String[] s = ftpPath.split("/", 2); if (s.length != 2) { return false; } String server = s[0]; String subPath = s[1]; ftpClient.setConnectTimeout(5000); ftpClient.connect(server); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); if (!ftpClient.login("anonymous", "")) { return false; } ftpClient.enterLocalPassiveMode(); // bug : mac doesnt allow ftp server connect through through local firewall - thus use passive server try (FileOutputStream fos = new FileOutputStream(outFile)) { try { String path = subPath + "/"; FTPFile[] files = ftpClient.listFiles(path, filter); Optional<FTPFile> opt = Arrays.stream(files) .sorted((f1, f2) -> Integer.compare(f1.getName().length(), f2.getName().length())) .findFirst(); if (opt.isPresent()) { ftpClient.retrieveFile(path + opt.get().getName(), fos); } } finally { ftpClient.logout(); ftpClient.disconnect(); } } return true; } catch (IOException ex) { throw new UncheckedIOException(ex); } }
From source file:org.cryptomator.frontend.webdav.servlet.DavNode.java
@Override public DavFolder getCollection() { DavLocatorImpl parentLocator = locator.resolveParent(); if (parentLocator == null) { return null; } else {/* ww w . ja va 2s.com*/ Path parentPath = path.getParent(); BasicFileAttributes parentAttr; try { parentAttr = Files.readAttributes(parentPath, BasicFileAttributes.class); } catch (NoSuchFileException e) { parentAttr = null; } catch (IOException e) { throw new UncheckedIOException(e); } return factory.createFolder(parentLocator, parentPath, Optional.ofNullable(parentAttr), session); } }
From source file:org.apache.geode.distributed.LauncherIntegrationTestCase.java
private void givenPortInUse(final int port) { try {/* ww w.j a va 2 s . co m*/ givenPortInUse(port, InetAddress.getLocalHost()); } catch (UnknownHostException e) { throw new UncheckedIOException(e); } }
From source file:com.twentyn.patentSearch.Searcher.java
private List<Triple<Float, String, String>> executeQuery(Pair<IndexReader, IndexSearcher> readerSearcher, BooleanQuery query) throws UncheckedIOException { TopDocs topDocs;/*from w w w.j a v a 2 s.c o m*/ try { topDocs = readerSearcher.getRight().search(query, MAX_RESULTS_PER_QUERY); } catch (IOException e) { LOGGER.error("Caught IO exception when trying to run search for %s: %s", query, e.getMessage()); /* Wrap `e` in an unchecked exception to allow it to escape our call stack. The top level function with catch * and rethrow it as a normal IOException. */ throw new UncheckedIOException(e); } ScoreDoc[] scoreDocs = topDocs.scoreDocs; if (scoreDocs.length == 0) { LOGGER.debug("Search returned no results."); return Collections.emptyList(); } // ScoreDoc just contains a score and an id. We need to retrieve the documents' content using that id. /* Crux of the next bit: * Filter by score and convert from scoreDocs to document features. * No need to use `limit` here since we already had Lucene cap the result set size. */ return Arrays.stream(scoreDocs).filter(scoreDoc -> scoreDoc.score >= scoreThreshold).map(scoreDoc -> { // try { Pair<String, String> features = this .extractDocFeatures(readerSearcher.getLeft().document(scoreDoc.doc)); // Put the score first so the natural sort order is based on score. return Triple.of(scoreDoc.score, features.getLeft(), features.getRight()); } catch (IOException e) { // Yikes, this is v. bad. LOGGER.error("Caught IO exception when trying to read doc id %d: %s", scoreDoc.doc, e.getMessage()); throw new UncheckedIOException(e); // Same as above. } }).collect(Collectors.toList()); }
From source file:org.codice.ddf.configuration.migration.ExportMigrationContextImpl.java
@SuppressWarnings("PMD.DefaultPackage" /* designed to be called from ExportMigrationEntryImpl within this package */) OutputStream getOutputStreamFor(ExportMigrationEntryImpl entry) { try {// w ww . jav a 2 s . c om close(); // zip entries are always Unix style based on our convention final ZipEntry ze = new ZipEntry(id + '/' + entry.getName()); ze.setTime(entry.getLastModifiedTime()); // save the current modified time zipOutputStream.putNextEntry(ze); final OutputStream oos = new ProxyOutputStream(zipOutputStream) { @Override public void close() throws IOException { if (!(super.out instanceof ClosedOutputStream)) { super.out = ClosedOutputStream.CLOSED_OUTPUT_STREAM; zipOutputStream.closeEntry(); } } @Override protected void handleIOException(IOException e) throws IOException { super.handleIOException(new ExportIOException(e)); } }; CipherOutputStream cos = cipherUtils.getCipherOutputStream(oos); this.currentOutputStream = cos; return cos; } catch (IOException e) { throw new UncheckedIOException(e); } }