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(String message, IOException cause) 

Source Link

Document

Constructs an instance of this class.

Usage

From source file:am.ik.sendgrid.util.JsonCodec.java

public static <T> Function<InputStream, T> decode(ObjectMapper objectMapper, Class<T> type) {
    return inputStream -> {
        try (InputStream in = inputStream) {
            return objectMapper.readValue(in, type);
        } catch (IOException e) {
            throw new UncheckedIOException("Unable to parse JSON Payload", e);
        }/*from w  w w.j  a  va2  s . co m*/
    };
}

From source file:am.ik.sendgrid.util.JsonCodec.java

public static <T> Function<InputStream, T> decode(ObjectMapper objectMapper, TypeReference<T> type) {
    return inputStream -> {
        try (InputStream in = inputStream) {
            return objectMapper.readValue(in, type);
        } catch (IOException e) {
            throw new UncheckedIOException("Unable to parse JSON Payload", e);
        }//w  w  w .j  a v  a2s.c o  m
    };
}

From source file:org.dbflute.intro.app.logic.core.FlutyFileLogic.java

public String readFile(File textFile) {
    try {//from  w  w w . j a  va  2s. c o m
        return FileUtils.readFileToString(textFile, BASIC_ENCODING);
    } catch (IOException e) {
        throw new UncheckedIOException("Cannot read the text file: " + textFile, e);
    }
}

From source file:dk.dbc.kafka.logformat.LogEventMapper.java

public String marshall(Object object) {
    final StringWriter stringWriter = new StringWriter();
    try {/*from   w w w  .  j a  v a2  s  .  co m*/
        objectMapper.writeValue(stringWriter, object);
    } catch (IOException e) {
        throw new UncheckedIOException("Exception caught when trying to marshall to JSON", e);
    }
    return stringWriter.toString();
}

From source file:org.dbflute.intro.app.logic.core.FlutyFileLogic.java

public void writeFile(File textFile, String content) {
    try {/*from   ww w .j a v a2 s.co  m*/
        FileUtils.write(textFile, content, BASIC_ENCODING);
    } catch (IOException e) {
        throw new UncheckedIOException("Cannot write the text file: " + textFile, e);
    }
}

From source file:dk.dbc.kafka.logformat.LogEventMapper.java

public LogEvent unmarshall(byte[] json) {
    try {// www . j  a  v  a 2 s. co m
        return objectMapper.readValue(json, LogEvent.class);
    } catch (IOException e) {
        throw new UncheckedIOException("Exception caught when trying to unmarshall JSON to LogEvent object", e);
    }
}

From source file:org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.java

/**
 * Creates an ElasticsearchTable./*  www  .j a  v  a2s .  c  o m*/
 * @param client low-level ES rest client
 * @param mapper Jackson API
 * @param indexName elastic search index
 * @param typeName elastic searh index type
 */
ElasticsearchTable(RestClient client, ObjectMapper mapper, String indexName, String typeName) {
    super(indexName, typeName, Objects.requireNonNull(mapper, "mapper"));
    this.restClient = Objects.requireNonNull(client, "client");
    try {
        this.version = detectVersion(client, mapper);
    } catch (IOException e) {
        final String message = String.format(Locale.ROOT, "Couldn't detect ES version " + "for %s/%s",
                indexName, typeName);
        throw new UncheckedIOException(message, e);
    }

}

From source file:org.trellisldp.file.FileUtils.java

/**
 * Fetch a stream of files in the provided directory path.
 * @param path the directory path/*from w w w  .j  av a  2 s.co m*/
 * @return a stream of filenames
 */
public static Stream<Path> uncheckedList(final Path path) {
    try {
        return Files.list(path);
    } catch (final IOException ex) {
        throw new UncheckedIOException("Error fetching file list", ex);
    }
}

From source file:platform.tooling.support.Runner.java

private Result installRemoteTool(Result result) {
    // download/*from www. ja  va2 s  .  c o m*/
    var version = request.getVersion();
    var toolArchive = tool.computeArchive(version);
    var toolUri = tool.computeUri(version);
    var toolArchivePath = toolPath.resolve(toolArchive);
    if (Files.notExists(toolArchivePath)) {
        var timeout = (int) TimeUnit.MILLISECONDS.convert(9, TimeUnit.SECONDS);
        try {
            FileUtils.copyURLToFile(toolUri.toURL(), toolArchivePath.toFile(), timeout, timeout);
        } catch (IOException e) {
            throw new UncheckedIOException("Loading tool failed: " + toolUri, e);
        }
    }

    // extract
    var jarTool = ToolProvider.findFirst("jar").orElseThrow();
    var stringWriter = new StringWriter();
    var printWriter = new PrintWriter(stringWriter);
    jarTool.run(printWriter, printWriter, "--list", "--file", toolArchivePath.toString());
    var toolFolderName = stringWriter.toString().split("\\R")[0];
    var toolFolderPath = toolPath.resolve(toolFolderName);
    if (Files.notExists(toolFolderPath)) {
        try {
            jarTool.run(System.out, System.err, "--extract", "--file", toolArchivePath.toString());
            FileUtils.moveDirectoryToDirectory(Paths.get(toolFolderName).toFile(), toolPath.toFile(), true);
        } catch (IOException e) {
            throw new UncheckedIOException("Extracting tool failed: " + toolUri, e);
        }
    }
    result.toolHome = toolFolderPath.normalize().toAbsolutePath();

    // compute program entry point
    var executable = toolFolderPath.resolve(tool.computeExecutablePath());
    if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
        executable.toFile().setExecutable(true);
    }
    result.toolExecutable = executable;
    return result;
}

From source file:acmi.l2.clientmod.l2resources.Environment.java

private UnrealPackage getPackage(File f) throws UncheckedIOException {
    if (!pckgCache.containsKey(f)) {
        try (UnrealPackage up = new UnrealPackage(f, true, null, null)) {
            pckgCache.put(f, up);/*ww  w.j  a v a 2s  .com*/
        } catch (IOException e) {
            throw new UncheckedIOException("Couldn't load package " + f.getName(), e);
        }
    }

    return pckgCache.get(f);
}