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.everit.blobstore.jdbc.test.AbstractJdbcBlobstoreTest.java

@Before
public void before() {
    DatabaseAccessParametersDTO databaseAccessParameters = resolveDatabaseAccessParameters();

    skipped = databaseAccessParameters == null;
    Assume.assumeFalse("Tests are not enabled for database " + getDatabaseTestAttributes().dbName, skipped);

    try {//from  w  ww  .  j  a  v a 2  s . c  o m
        transactionManager = new GeronimoTransactionManager(6000);
    } catch (XAException e) {
        throw new RuntimeException(e);
    }

    XADataSource xaDataSource = createXADataSource(databaseAccessParameters);

    managedDataSource = createManagedDataSource(transactionManager, xaDataSource);

    try (Connection connection = managedDataSource.getConnection()) {
        DatabaseConnection databaseConnection = new JdbcConnection(connection);

        Liquibase liquibase = new Liquibase("META-INF/liquibase/org.everit.blobstore.jdbc.changelog.xml",
                new ClassLoaderResourceAccessor(), databaseConnection);

        String sqlOutputFolder = System.getProperty("blobstore.sql.outputFolder");
        if (sqlOutputFolder != null) {
            File folder = new File(sqlOutputFolder);
            folder.mkdirs();

            File outputFile = new File(folder, "blobstore-" + getDatabaseTestAttributes().dbName + ".sql");

            try (FileWriter fw = new FileWriter(outputFile, true)) {

                liquibase.update((Contexts) null, fw);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        liquibase.update((Contexts) null);
    } catch (LiquibaseException | SQLException e) {
        try {
            managedDataSource.close();
        } catch (SQLException e1) {
            e.addSuppressed(e1);
        }
        throw new RuntimeException(e);
    }

    blobstore = new JdbcBlobstore(managedDataSource);

    transactionPropagator = new JTATransactionPropagator(transactionManager);

}

From source file:de.siegmar.securetransfer.component.Cryptor.java

public byte[] decrypt(final byte[] src, final KeyIv keyIv) {
    try (final InputStream cryptIn = getCryptIn(new ByteArrayInputStream(src), keyIv)) {
        return ByteStreams.toByteArray(cryptIn);
    } catch (final IOException e) {
        throw new UncheckedIOException(e);
    }/*from   w  ww  .j a  va 2s. c  om*/
}

From source file:objective.taskboard.utils.ZipUtils.java

public static void zip(Stream<ZipStreamEntry> stream, OutputStream outputStream) {
    try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
        stream.forEach(ze -> {//w  w  w  .j  a  v  a  2 s.c  o  m
            ZipEntry newEntry = new ZipEntry(ze.getName());
            try {
                zipOutputStream.putNextEntry(newEntry);
                IOUtils.copy(ze.getInputStream(), zipOutputStream);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        stream.close();
    }
}

From source file:org.ajoberstar.reckon.core.git.GitInventorySupplier.java

@Override
public VcsInventory getInventory() {
    try (RevWalk walk = new RevWalk(repo)) {
        walk.setRetainBody(false);/*ww w.  java 2  s. c  om*/

        ObjectId headObjectId = repo.getRefDatabase().getRef("HEAD").getObjectId();

        if (headObjectId == null) {
            logger.debug("No HEAD commit. Presuming repo is empty.");
            return new VcsInventory(null, null, null, null, 0, null, null);
        }

        logger.debug("Found HEAD commit {}", headObjectId);

        RevCommit headCommit = walk.parseCommit(headObjectId);

        Set<TaggedVersion> taggedVersions = getTaggedVersions(walk);

        logger.debug("Found tagged versions: {}", taggedVersions);

        Version currentVersion = findCurrent(headCommit, taggedVersions.stream()).map(TaggedVersion::getVersion)
                .orElse(null);
        TaggedVersion baseNormal = findBase(walk, headCommit,
                taggedVersions.stream().filter(TaggedVersion::isNormal));
        TaggedVersion baseVersion = findBase(walk, headCommit, taggedVersions.stream());

        int commitsSinceBase = RevWalkUtils.count(walk, headCommit, baseNormal.getCommit());

        Set<TaggedVersion> parallelCandidates = findParallelCandidates(walk, headCommit, taggedVersions);

        Set<RevCommit> taggedCommits = taggedVersions.stream().map(TaggedVersion::getCommit)
                .collect(Collectors.toSet());
        Set<Version> parallelVersions = parallelCandidates.stream()
                .map(version -> findParallel(walk, headCommit, version, taggedCommits))
                // TODO Java 9 Optional::stream
                .flatMap(opt -> opt.isPresent() ? Stream.of(opt.get()) : Stream.empty())
                .collect(Collectors.toSet());

        Set<Version> claimedVersions = taggedVersions.stream().map(TaggedVersion::getVersion)
                .collect(Collectors.toSet());

        return new VcsInventory(headObjectId.getName(), currentVersion, baseVersion.getVersion(),
                baseNormal.getVersion(), commitsSinceBase, parallelVersions, claimedVersions);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

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

protected File givenControlFile(final String name) {
    try {/*  www .ja  v  a 2s  . c  om*/
        File file = new File(getWorkingDirectory(), name);
        assertThat(file.createNewFile()).isTrue();
        assertThat(file).exists();
        return file;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:nl.knaw.huygens.alexandria.dropwizard.cli.commands.AlexandriaCommand.java

private void uncheckedStore(File file, Object object) {
    try {//  ww  w. ja va  2s  . co  m
        mapper.writeValue(file, object);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:uk.trainwatch.osgb.codepoint.util.CodePointImport.java

private void importCode(Connection con, String table, Function<CSVRecord, String> code,
        Function<CSVRecord, String> name, File file) throws SQLException {

    try (CSVParser p = new CSVParser(new FileReader(file), CSVFormat.EXCEL)) {
        LOG.log(Level.INFO, () -> "Clearing down " + table);

        SQL.deleteIdTable(con, SCHEMA, table);
        try (Statement s = con.createStatement()) {
            s.executeUpdate("INSERT INTO " + SCHEMA + "." + table + " VALUES (0,'','')");
        }//from w  w  w .j  a va  2s  . co m

        try (PreparedStatement ps = con
                .prepareStatement("INSERT INTO " + SCHEMA + "." + table + " (code,name) VALUES(?,?)")) {

            p.getRecords().stream().collect(Collectors.toMap(code::apply, name::apply, (a, b) -> a))
                    .forEach(SQLBiConsumer.guard((c, n) -> SQL.executeUpdate(ps, c, n)));

            con.commit();

            LOG.log(Level.INFO, () -> "Imported " + p.getRecordNumber() + " entries into code table");
        }
    } catch (SQLException ex) {
        con.rollback();
        throw new UncheckedSQLException(ex);
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}

From source file:name.wramner.jmstools.analyzer.DataProvider.java

/**
 * Get a base64-encoded image for inclusion in an img tag with a chart with kilobytes per minute produced and
 * consumed./*from  w w w.  j a  va  2 s .  co m*/
 *
 * @return chart as base64 string.
 */
public String getBase64BytesPerMinuteImage() {
    TimeSeries timeSeriesConsumed = new TimeSeries("Consumed");
    TimeSeries timeSeriesProduced = new TimeSeries("Produced");
    TimeSeries timeSeriesTotal = new TimeSeries("Total");
    for (PeriodMetrics m : getMessagesPerMinute()) {
        Minute minute = new Minute(m.getPeriodStart());
        timeSeriesConsumed.add(minute, m.getConsumedBytes() / 1024);
        timeSeriesProduced.add(minute, m.getProducedBytes() / 1024);
        timeSeriesTotal.add(minute, m.getTotalBytes() / 1024);
    }
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(timeSeriesConsumed);
    timeSeriesCollection.addSeries(timeSeriesProduced);
    timeSeriesCollection.addSeries(timeSeriesTotal);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        JFreeChart chart = ChartFactory.createTimeSeriesChart("Kilobytes per minute", "Time", "Bytes (k)",
                timeSeriesCollection);
        chart.getPlot().setBackgroundPaint(Color.WHITE);
        ChartUtilities.writeChartAsPNG(bos, chart, 1024, 500);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return "data:image/png;base64," + Base64.getEncoder().encodeToString(bos.toByteArray());
}

From source file:org.cryptomator.frontend.webdav.servlet.DavFolder.java

@Override
public DavResourceIterator getMembers() {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
        List<DavResource> children = new ArrayList<>();
        for (Path childPath : stream) {
            BasicFileAttributes childAttr = Files.readAttributes(childPath, BasicFileAttributes.class);
            DavLocatorImpl childLocator = locator.resolveChild(childPath.getFileName().toString());
            if (childAttr.isDirectory()) {
                DavFolder childFolder = factory.createFolder(childLocator, childPath, Optional.of(childAttr),
                        session);/*from  w  w  w. j  a v  a  2 s . co m*/
                children.add(childFolder);
            } else if (childAttr.isRegularFile()) {
                DavFile childFile = factory.createFile(childLocator, childPath, Optional.of(childAttr),
                        session);
                children.add(childFile);
            }
        }
        return new DavResourceIteratorImpl(children);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.github.blindpirate.gogradle.util.IOUtils.java

public static String toString(File file) {
    try (InputStream is = new FileInputStream(file)) {
        return org.apache.commons.io.IOUtils.toString(is, DEFAULT_CHARSET);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }/*ww w . j a v a2 s.  com*/
}