Example usage for java.io UncheckedIOException UncheckedIOException

List of usage examples for java.io UncheckedIOException UncheckedIOException

Introduction

In this page you can find the example usage for java.io UncheckedIOException UncheckedIOException.

Prototype

public UncheckedIOException(IOException cause) 

Source Link

Document

Constructs an instance of this class.

Usage

From source file:org.wso2.carbon.launcher.test.OSGiLibBundleDeployerTest.java

private static void delete(Path path) throws IOException {
    Path osgiRepoPath = Paths.get(carbonHome, Constants.OSGI_REPOSITORY);
    Files.list(path).filter(child -> !osgiRepoPath.equals(child) && Files.isDirectory(child)).forEach(child -> {
        try {//from  w w w  . ja  v  a 2  s.  c o  m
            FileUtils.deleteDirectory(child.toFile());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}

From source file:com.github.blindpirate.gogradle.crossplatform.DefaultGoBinaryManager.java

private Path downloadArchive(String version) {
    String url = injectVariables(setting.getGoBinaryDownloadTemplate(), version);
    String archiveFileName = injectVariables(FILENAME, version);
    File goBinaryCachePath = globalCacheManager.getGlobalGoBinCacheDir(archiveFileName);
    forceMkdir(goBinaryCachePath.getParentFile());
    LOGGER.warn("downloading {} -> {}", url, goBinaryCachePath.getAbsolutePath());
    try {//from   w  w w  . j a va2  s.  co m
        httpUtils.download(url, goBinaryCachePath.toPath());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return goBinaryCachePath.toPath();
}

From source file:com.joyent.manta.client.MantaDirectoryListingIterator.java

@Override
public synchronized Map<String, Object> next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }/*from  w w w. j av  a 2  s . co m*/

    try {
        String line = nextLine.getAndSet(br.readLine());
        lines.incrementAndGet();

        if (line == null) {
            selectReader();

            if (finished.get()) {
                throw new NoSuchElementException();
            }

            line = nextLine.getAndSet(br.readLine());
        }

        final Map<String, Object> lookup = mapper.readValue(line, new TypeReference<Map<String, Object>>() {
        });
        final String name = Objects.toString(lookup.get("name"));

        Validate.notNull(name, "Name must not be null in JSON input");

        /* Explicitly set the path of the object here so that we don't need
         * to create a new instance of MantaObjectConversionFunction per
         * object being read. */
        lookup.put("path", path);

        this.lastMarker = name;

        return lookup;

    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.apache.geode.distributed.LauncherIntegrationTestCase.java

private int readPidFile(final File pidFile) {
    try {/*  www .ja v  a2  s.c om*/
        assertTrue(pidFile.exists());
        try (BufferedReader reader = new BufferedReader(new FileReader(pidFile))) {
            return Integer.parseInt(StringUtils.trim(reader.readLine()));
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.opencb.opencga.storage.hadoop.variant.metadata.HBaseStudyConfigurationManager.java

private void updateStudiesSummary(BiMap<String, Integer> studies, QueryOptions options) {
    try {/*from ww  w  .  j av  a  2s . c  o  m*/
        VariantTableDriver.createVariantTableIfNeeded(genomeHelper, tableName, getConnection());
        try (Table table = getConnection().getTable(TableName.valueOf(tableName))) {
            byte[] bytes = objectMapper.writeValueAsBytes(studies);
            Put put = new Put(studiesRow);
            put.addColumn(genomeHelper.getColumnFamily(), studiesSummaryColumn, bytes);
            table.put(put);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:be.error.rpi.dac.dimmer.builder.Dimmer.java

private void dim(BigDecimal targetValue) throws IOException {
    if (dimmerBackend == I2C) {
        byte[] b = convertPercentageToDacBytes(targetValue);
        getInstance().getI2CCommunicator().write(boardAddress, channel, b);
    } else {/* www .  j a  v  a 2  s.  c  om*/
        getInstance().doWithLucidControl(boardAddress, (lucidControlAO4) -> {
            try {
                lucidControlAO4.setIo(channel, new ValueVOS2(convertPercentageTo10Volt(targetValue)));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
    }
}

From source file:org.cryptomator.cryptofs.CryptoFileSystemImpl.java

/**
 * @param cleartextPath the path to the file
 * @param type the Class object corresponding to the file attribute view
 * @param options future use//from www . j a v  a 2s  .co  m
 * @return a file attribute view of the specified type, or <code>null</code> if the attribute view type is not available
 * @see CryptoFileAttributeViewProvider#getAttributeView(Path, Class)
 */
<V extends FileAttributeView> V getFileAttributeView(CryptoPath cleartextPath, Class<V> type,
        LinkOption... options) {
    try {
        Path ciphertextDirPath = cryptoPathMapper.getCiphertextDirPath(cleartextPath);
        if (Files.notExists(ciphertextDirPath) && cleartextPath.getNameCount() > 0) {
            Path ciphertextFilePath = cryptoPathMapper.getCiphertextFilePath(cleartextPath,
                    CiphertextFileType.FILE);
            return fileAttributeViewProvider.getAttributeView(ciphertextFilePath, type);
        } else {
            return fileAttributeViewProvider.getAttributeView(ciphertextDirPath, type);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Path write(Path path, Iterable<? extends CharSequence> lines, OpenOption... options) {
    if (options.length == 0) {
        options = new OpenOption[] { CREATE_NEW };
    }//from   w  ww .j av a  2 s  .  co m
    try {
        File parent = path.getParent().toFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        return path.toString().endsWith(".gz") ? GZIPFiles.write(path, lines, UTF_8, options)
                : path.toString().endsWith(".bz2") ? BZIP2Files.write(path, lines, UTF_8, options)
                        : Files.write(path, lines, UTF_8, options);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.flowable.cmmn.rest.service.BaseSpringRestTestCase.java

protected CloseableHttpResponse internalExecuteRequest(HttpUriRequest request, int expectedStatusCode,
        boolean addJsonContentType) {
    try {//  www  .j a  va2s .c  o m
        if (addJsonContentType && request.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
            // Revert to default content-type
            request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
        }
        CloseableHttpResponse response = client.execute(request);
        Assert.assertNotNull(response.getStatusLine());

        int responseStatusCode = response.getStatusLine().getStatusCode();
        if (expectedStatusCode != responseStatusCode) {
            LOGGER.info("Wrong status code : {}, but should be {}", responseStatusCode, expectedStatusCode);
            if (response.getEntity() != null) {
                LOGGER.info("Response body: {}", IOUtils.toString(response.getEntity().getContent(), "utf-8"));
            }
        }

        Assert.assertEquals(expectedStatusCode, responseStatusCode);
        httpResponses.add(response);
        return response;

    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.hurence.logisland.plugin.PluginManager.java

private static void installPlugin(String artifact, String logislandHome) {
    Optional<ModuleInfo> moduleInfo = findPluginMeta().entrySet().stream()
            .filter(e -> artifact.equals(e.getKey().getArtifact())).map(Map.Entry::getKey).findFirst();
    if (moduleInfo.isPresent()) {
        System.err//ww  w  .  j a  v  a  2  s .  c  o m
                .println("A component already matches the artifact " + artifact + ". Please remove it first.");
        System.exit(-1);
    }

    try {

        IvySettings settings = new IvySettings();
        settings.load(new File(logislandHome, "conf/ivy.xml"));

        Ivy ivy = Ivy.newInstance(settings);
        ivy.bind();

        System.out.println("\nDownloading dependencies. Please hold on...\n");

        String parts[] = Arrays.stream(artifact.split(":")).map(String::trim).toArray(a -> new String[a]);
        if (parts.length != 3) {
            throw new IllegalArgumentException(
                    "Unrecognized artifact format. It should be groupId:artifactId:version");
        }
        ModuleRevisionId revisionId = new ModuleRevisionId(new ModuleId(parts[0], parts[1]), parts[2]);
        Set<ArtifactDownloadReport> toBePackaged = downloadArtifacts(ivy, revisionId,
                new String[] { "default", "compile", "runtime" });

        ArtifactDownloadReport artifactJar = toBePackaged.stream()
                .filter(a -> a.getArtifact().getModuleRevisionId().equals(revisionId)).findFirst()
                .orElseThrow(() -> new IllegalStateException("Unable to find artifact " + artifact
                        + ". Please check the name is correct and the repositories on ivy.xml are correctly configured"));

        Manifest manifest = new JarFile(artifactJar.getLocalFile()).getManifest();
        File libDir = new File(logislandHome, "lib");

        if (manifest.getMainAttributes().containsKey(ManifestAttributes.MODULE_ARTIFACT)) {
            org.apache.commons.io.FileUtils.copyFileToDirectory(artifactJar.getLocalFile(), libDir);
            //we have a logisland plugin. Just copy it
            System.out.println(String.format("Found logisland plugin %s version %s\n" + "It will provide:",
                    manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_NAME),
                    manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION)));
            Arrays.stream(manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_EXPORTS).split(","))
                    .map(String::trim).forEach(s -> System.out.println("\t" + s));

        } else {
            System.out.println("Repackaging artifact and its dependencies");
            Set<ArtifactDownloadReport> environment = downloadArtifacts(ivy, revisionId,
                    new String[] { "provided" });
            Set<ArtifactDownloadReport> excluded = toBePackaged.stream()
                    .filter(adr -> excludeGroupIds.stream()
                            .anyMatch(s -> s.matches(adr.getArtifact().getModuleRevisionId().getOrganisation()))
                            || excludedArtifactsId.stream().anyMatch(
                                    s -> s.matches(adr.getArtifact().getModuleRevisionId().getName())))
                    .collect(Collectors.toSet());

            toBePackaged.removeAll(excluded);
            environment.addAll(excluded);

            Repackager rep = new Repackager(artifactJar.getLocalFile(), new LogislandPluginLayoutFactory());
            rep.setMainClass("");
            File destFile = new File(libDir, "logisland-component-" + artifactJar.getLocalFile().getName());
            rep.repackage(destFile, callback -> toBePackaged.stream().filter(adr -> adr.getLocalFile() != null)
                    .filter(adr -> !adr.getArtifact().getModuleRevisionId().equals(revisionId))
                    .map(adr -> new Library(adr.getLocalFile(), LibraryScope.COMPILE)).forEach(library -> {
                        try {
                            callback.library(library);
                        } catch (IOException e) {
                            throw new UncheckedIOException(e);
                        }
                    }));
            Thread.currentThread().setContextClassLoader(new URLClassLoader(
                    environment.stream().filter(adr -> adr.getLocalFile() != null).map(adr -> {
                        try {
                            return adr.getLocalFile().toURI().toURL();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }).toArray(a -> new URL[a]), Thread.currentThread().getContextClassLoader()));
            //now clean up package and write the manifest
            String newArtifact = "com.hurence.logisland.repackaged:" + parts[1] + ":" + parts[2];
            LogislandRepackager.execute(destFile.getAbsolutePath(), "BOOT-INF/lib-provided", parts[2],
                    newArtifact, "Logisland Component for " + artifact, "Logisland Component for " + artifact,
                    new String[] { "org.apache.kafka.*" }, new String[0],
                    "org.apache.kafka.connect.connector.Connector");
        }
        System.out.println("Install done!");
    } catch (Exception e) {
        System.err.println("Unable to install artifact " + artifact);
        e.printStackTrace();
        System.exit(-1);
    }

}