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:newcontroller.handler.impl.DefaultRequest.java

@Override
public <T> T body(Class<T> clazz) {
    MediaType mediaType = MediaType.parseMediaType(this.request.getContentType());
    HttpMessageConverter converter = HttpMessageConvertersHelper.findConverter(this.converters, clazz,
            mediaType);//from   w w  w  .j a va  2s . c  o m
    try {
        return clazz.cast(converter.read(clazz, new ServletServerHttpRequest(this.request)));
    } catch (IOException e) {
        throw new UncheckedIOException(e); // TODO
    }
}

From source file:org.apache.bookkeeper.tools.perf.dlog.PerfSegmentReader.java

@Override
protected void execute(Namespace namespace) throws Exception {
    List<DistributedLogManager> managers = new ArrayList<>(flags.numLogs);
    for (int i = 0; i < flags.numLogs; i++) {
        String logName = String.format(flags.logName, i);
        managers.add(namespace.openLog(logName));
    }/*from ww w  .  j  a  va 2  s  . c o m*/
    log.info("Successfully open {} logs", managers.size());

    // Get all the log segments
    final List<Pair<DistributedLogManager, LogSegmentMetadata>> segments = managers.stream()
            .flatMap(manager -> {
                try {
                    return manager.getLogSegments().stream().map(segment -> Pair.of(manager, segment));
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }).collect(Collectors.toList());

    final List<Split> splits = segments.stream()
            .flatMap(entry -> getNumSplits(entry.getLeft(), entry.getRight()).stream())
            .collect(Collectors.toList());

    // register shutdown hook to aggregate stats
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        isDone.set(true);
        printAggregatedStats(cumulativeRecorder);
    }));

    ExecutorService executor = Executors.newFixedThreadPool(flags.numThreads);
    try {
        for (int i = 0; i < flags.numThreads; i++) {
            final int idx = i;
            final List<Split> splitsThisThread = splits.stream()
                    .filter(split -> splits.indexOf(split) % flags.numThreads == idx)
                    .collect(Collectors.toList());
            executor.submit(() -> {
                try {
                    read(splitsThisThread);
                } catch (Exception e) {
                    log.error("Encountered error at writing records", e);
                }
            });
        }
        log.info("Started {} write threads", flags.numThreads);
        reportStats();
    } finally {
        executor.shutdown();
        if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
            executor.shutdownNow();
        }
        managers.forEach(manager -> manager.asyncClose());
    }
}

From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java

public static void delete(Path path) {
    try {// www .  j a  v  a2s. c om
        Files.delete(path);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.trellisldp.test.TestUtils.java

/**
 * Parse a JSON entity into the desired type.
 * @param entity the entity//from w w w  . ja va  2 s. c o m
 * @param valueType the type reference
 * @param <T> the intended return type
 * @return the entity as the desired type
 */
public static <T> T readEntityAsJson(final Object entity, final TypeReference<T> valueType) {
    try {
        return MAPPER.readValue(readEntityAsString(entity), valueType);
    } catch (final IOException ex) {
        throw new UncheckedIOException(ex);
    }
}

From source file:com.github.horrorho.inflatabledonkey.chunk.store.disk.DiskChunk.java

@Override
public long copyTo(OutputStream output) throws UncheckedIOException {
    try (InputStream input = Files.newInputStream(file, READ)) {
        long bytes = IOUtils.copyLarge(input, output);

        logger.debug("-- copyTo() - written (bytes): {}", bytes);
        return bytes;

    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }//w  w  w  .j av a2s . com
}

From source file:no.imr.stox.functions.processdata.DefineAgeErrorMatrix.java

/**
 * define temporal covariates//from   w  w  w  . j  a va 2  s  .  com
 *
 * @param input contains Polygon file name DataTypeDescription.txt
 * @return
 */
@Override
public Object perform(Map<String, Object> input) {
    ProcessDataBO pd = (ProcessDataBO) input.get(Functions.PM_DEFINEAGEERRORMATRIX_PROCESSDATA);
    MatrixBO ageError = pd.getMatrix(AbndEstProcessDataUtil.TABLE_AGEERROR);
    String defMethod = (String) input.get(Functions.PM_DEFINEAGEERRORMATRIX_DEFINITIONMETHOD);
    ILogger logger = (ILogger) input.get(Functions.PM_LOGGER);
    if (defMethod == null || defMethod.equals(Functions.DEFINITIONMETHOD_USEPROCESSDATA)) {
        // Use existing, do not read from file.
        return pd;
    }
    String fileName = ProjectUtils.resolveParameterFileName(
            (String) input.get(Functions.PM_DEFINEAGEERRORMATRIX_FILENAME),
            (String) input.get(Functions.PM_PROJECTFOLDER));
    if (fileName == null) {
        return pd;
    }
    List<String> lines;
    try {
        lines = FileUtils.readLines(new File(fileName));
        // Loop through the lines
        if (lines.isEmpty()) {
            return pd;
        }
        String[] realAges = lines.get(0).split("\t");
        if (lines.size() != realAges.length) {
            return null; // equal dimension size on real and read ages
        }
        lines.remove(0); // Remove header
        for (String line : lines) {
            if (line.startsWith("#")) {
                continue;
            }
            String[] elements = line.split("\t");
            if (elements.length != realAges.length) {
                return null;
            }
            String readAge = elements[0];
            for (int iRealAge = 1; iRealAge < elements.length; iRealAge++) {
                String realAge = realAges[iRealAge];
                Double p = Conversion.safeStringtoDoubleNULL(elements[iRealAge]);
                if (p == null || p.equals(0d)) {
                    continue;
                }
                ageError.setRowColValue(realAge, readAge, p);
            }
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
    return pd;
}

From source file:io.werval.modules.json.JacksonJSON.java

@Override
public JsonNode fromJSON(byte[] json) {
    try {//from  w  ww . j a  v a 2 s  . c om
        return mapper.readTree(json);
    } catch (JsonProcessingException ex) {
        throw new JsonPluginException(ex);
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}

From source file:org.datacleaner.components.machinelearning.MLClassificationTransformer.java

@Initialize
public void init() {
    try {/*  www .  ja v  a 2s  .  c om*/
        final byte[] bytes = Files.toByteArray(modelFile);
        classifier = (MLClassifier) SerializationUtils.deserialize(bytes);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.everit.json.schema.IssueTest.java

private Schema loadSchema() {
    Optional<File> schemaFile = fileByName("schema.json");
    try {//from  w w w  .ja  v a2  s . c om
        if (schemaFile.isPresent()) {
            JSONObject schemaObj = new JSONObject(new JSONTokener(new FileInputStream(schemaFile.get())));
            return SchemaLoader.load(schemaObj);
        }
        throw new RuntimeException(issueDir.getCanonicalPath() + "/schema.json is not found");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java

public static Path copy(Path source, Path target, CopyOption... options) {
    try {//from w w  w . j av a2  s .  c  o  m
        return Files.copy(source, target, options);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}