List of usage examples for java.io UncheckedIOException UncheckedIOException
public UncheckedIOException(IOException cause)
From source file:com.joyent.manta.client.crypto.AbstractMantaEncryptedObjectInputStreamTest.java
AbstractMantaEncryptedObjectInputStreamTest() { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); this.testURL = classLoader.getResource("test-data/chaucer.txt"); try {/*w w w.j av a 2 s.c o m*/ testFile = Paths.get(testURL.toURI()); } catch (URISyntaxException e) { throw new AssertionError(e); } this.plaintextSize = (int) testFile.toFile().length(); try (InputStream in = this.testURL.openStream()) { this.plaintextBytes = IOUtils.readFully(in, plaintextSize); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:uk.trainwatch.util.config.impl.HttpConfiguration.java
private synchronized void loadConfiguration() { if (configuration == null) { // Don't write uri as is as we may expose security details LOG.log(Level.INFO,/*from w w w . ja v a 2s.c o m*/ () -> "Retrieving config " + uri.getScheme() + "://" + uri.getHost() + uri.getPath()); try (CloseableHttpClient client = HttpClients.createDefault()) { int retry = 0; do { try { if (retry > 0) { LOG.log(Level.INFO, "Sleeping {0}ms attempt {1}/{2}", new Object[] { RETRY_DELAY, retry, MAX_RETRY }); Thread.sleep(RETRY_DELAY); } HttpGet get = new HttpGet(uri); get.setHeader("User-Agent", "Area51 Configuration/1.0"); try (CloseableHttpResponse response = client.execute(get)) { switch (response.getStatusLine().getStatusCode()) { case 200: case 304: try (InputStream is = response.getEntity().getContent()) { try (JsonReader r = Json.createReader(new InputStreamReader(is))) { configuration = new MapConfiguration( MapBuilder.fromJsonObject(r.readObject()).build()); return; } } default: LOG.log(Level.WARNING, () -> "Error " + uri.getScheme() + "://" + uri.getHost() + uri.getPath() + " " + response.getStatusLine().getStatusCode()); } } } catch (ConnectException ex) { if (retry < MAX_RETRY) { LOG.log(Level.WARNING, () -> "Failed " + ex.getMessage()); } else { throw ex; } } catch (InterruptedException ex) { LOG.log(Level.SEVERE, null, ex); } retry++; } while (retry < MAX_RETRY); } catch (IOException ex) { throw new UncheckedIOException(ex); } configuration = EmptyConfiguration.INSTANCE; } }
From source file:org.opencb.opencga.storage.hadoop.variant.converters.annotation.HBaseToVariantAnnotationConverter.java
@Override public VariantAnnotation convert(Result result) { byte[] value = result.getValue(columnFamily, VariantPhoenixHelper.VariantColumn.FULL_ANNOTATION.bytes()); if (ArrayUtils.isNotEmpty(value)) { try {// ww w. j av a 2 s. c o m return objectMapper.readValue(value, VariantAnnotation.class); } catch (IOException e) { throw new UncheckedIOException(e); } } return null; }
From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) { try {// w ww .jav a 2 s .c o m return Files.createTempDirectory(prefix, attrs); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static void copyDependencies(final File srcDir, final File destDir, final Set<String> subpackages) { try {/*from w ww. j a v a 2s. c o m*/ Assert.isTrue(dirIsEmpty(destDir)); DependencyInstallFileFilter filter = DependencyInstallFileFilter.subpackagesFilter(srcDir, subpackages); FileUtils.copyDirectory(srcDir, destDir, filter); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:nl.knaw.huygens.alexandria.dropwizard.cli.commands.DiffCommand.java
private void doDiff(final TAGStore store, final CLIContext context, final String filename, final Optional<String> documentName) { Long documentId = getIdForExistingDocument(documentName.get()); TAGDocument original = store.getDocument(documentId); String viewName = context.getActiveView(); TAGView tagView = MAIN_VIEW.equals(viewName) ? TAGViews.getShowAllMarkupView(store) : getExistingView(viewName, store, context); File editedFile = workFilePath(filename).toFile(); try {/*from w w w.j ava2 s .com*/ String newTAGML = FileUtils.readFileToString(editedFile, StandardCharsets.UTF_8); TAGMLImporter importer = new TAGMLImporter(store); TAGDocument edited = importer.importTAGML(newTAGML); TAGComparison comparison = new TAGComparison(original, tagView, edited); if (MAIN_VIEW.equals(viewName)) { System.out.printf("diff for %s:%n", filename); } else { System.out.printf("diff for %s, using view %s:%n", filename, viewName); } if (comparison.hasDifferences()) { System.out.printf("%s%n", String.join(System.lineSeparator(), comparison.getDiffLines())); } else { System.out.println("no changes"); } } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:com.linkedin.gradle.python.tasks.Flake8Task.java
public void preExecution() { PythonDetails flake8Python = getPythonDetails(); File flake8Exec = flake8Python.getVirtualEnvironment().findExecutable("flake8"); /*/*from w w w .java 2s. c o m*/ Modified to only include folders that exist. if no folders exist, then the task isn't actually run. */ PythonExtension pythonExtension = getPythonExtension(); List<String> paths = new ArrayList<>(); if (getProject().file(pythonExtension.srcDir).exists()) { log.info("Flake8: adding {}", pythonExtension.srcDir); paths.add(pythonExtension.srcDir); } else { log.info("Flake8: srcDir doesn't exist"); } if (getProject().file(pythonExtension.testDir).exists()) { log.info("Flake8: adding {}", pythonExtension.testDir); paths.add(pythonExtension.testDir); } else { log.info("Flake8: testDir doesn't exist"); } args(Arrays.asList(flake8Exec.getAbsolutePath(), "--config", pythonExtension.setupCfg)); // creating a flake8 config file if one doesn't exist, this prevents "file not found" issues. File cfgCheck = getProject().file(pythonExtension.setupCfg); if (!cfgCheck.exists()) { log.info("Flake8 config file doesn't exist, creating default"); try { FileUtils.write(cfgCheck, "[flake8]"); } catch (IOException e) { throw new UncheckedIOException(e); } } else { log.info("Flake8 config file exists"); } args(paths); }
From source file:org.opencb.opencga.storage.hadoop.variant.metadata.HBaseStudyConfigurationManager.java
@Override public long lockStudy(int studyId, long lockDuration, long timeout) throws InterruptedException, TimeoutException { try {/*from w ww .jav a 2 s. com*/ VariantTableDriver.createVariantTableIfNeeded(genomeHelper, tableName, getConnection()); return lock.lock(Bytes.toBytes(studyId + "_LOCK"), lockDuration, timeout); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.cryptomator.frontend.webdav.servlet.DavFolder.java
private void addMemberFile(DavFile memberFile, InputStream inputStream) { try (ReadableByteChannel src = Channels.newChannel(inputStream); // WritableByteChannel dst = Files.newByteChannel(memberFile.path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { ByteStreams.copy(src, dst);//ww w . j a v a2 s. com } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java
public static void createFile(Path path, FileAttribute<?>... attrs) { try {/* w ww .j a v a2s.com*/ Files.createFile(path, attrs); } catch (IOException e) { throw new UncheckedIOException(e); } }