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:eu.crydee.stanfordcorenlp.Tokenizer.java

/**
 * Wrapper around Stanford CoreNLP to tokenize text.
 *
 * Give it an input dir of text files with --input-dir and it'll ouput
 * tokenized versions, one sentence per line with space separated words to
 * --output-dir (defaults to out/).//from   w  ww  . j av a  2 s  .  c o m
 *
 * @param args CLI args. Example: --input-dir my-input --output-dir
 * my-output.
 */
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("stanford-corenlp-tokenizer-wrapper")
            .description("Converts Mediawiki dumps to text.");
    parser.addArgument("-i", "--input-dir").required(true).help("Path of the input text files directory.");
    parser.addArgument("-o", "--output-dir").help("Path of the output text files directory.").setDefault("out");
    Params params = new Params();
    try {
        parser.parseArgs(args, params);
    } catch (ArgumentParserException ex) {
        System.err.println("Could not parse arguments: " + ex.getMessage());
        System.exit(1);
    }
    Tokenizer tokenizer = new Tokenizer();

    try {
        Files.list(Paths.get(params.inDirPath)).filter(Files::isRegularFile).map(Path::toFile).map(f -> {
            try {
                return Pair.of(f.getName(), FileUtils.readFileToString(f, StandardCharsets.UTF_8));
            } catch (IOException ex) {
                System.err.println("Could not read input text file: " + ex.getLocalizedMessage());
                throw new UncheckedIOException(ex);
            }
        }).forEach(p -> {
            String text = tokenizer.tokenizeAndSentenceSplit(p.getRight());
            try {
                FileUtils.writeStringToFile(Paths.get(params.outDirpath, p.getLeft()).toFile(), text,
                        StandardCharsets.UTF_8);
            } catch (IOException ex) {
                System.err.println("Could not write output text file: " + ex.getLocalizedMessage());
            }
        });
    } catch (IOException ex) {
        System.err.println("Could not read from input directory: " + ex.getLocalizedMessage());
    }
}

From source file:com.act.lcms.db.analysis.BestMoleculesPickerFromLCMSIonAnalysis.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/* ww w . ja v a  2  s. co m*/
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        HELP_FORMATTER.printHelp(BestMoleculesPickerFromLCMSIonAnalysis.class.getCanonicalName(), HELP_MESSAGE,
                opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(BestMoleculesPickerFromLCMSIonAnalysis.class.getCanonicalName(), HELP_MESSAGE,
                opts, null, true);
        System.exit(1);
    }

    List<String> positiveReplicateResults = new ArrayList<>(
            Arrays.asList(cl.getOptionValues(OPTION_INPUT_FILES)));

    if (cl.hasOption(OPTION_MIN_OF_REPLICATES)) {
        HitOrMissReplicateFilterAndTransformer transformer = new HitOrMissReplicateFilterAndTransformer();

        List<IonAnalysisInterchangeModel> models = positiveReplicateResults.stream().map(file -> {
            try {
                return IonAnalysisInterchangeModel.loadIonAnalysisInterchangeModelFromFile(file);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }).collect(Collectors.toList());

        IonAnalysisInterchangeModel transformedModel = IonAnalysisInterchangeModel
                .filterAndOperateOnMoleculesFromMultipleReplicateModels(models, transformer);

        printInchisAndIonsToFile(transformedModel, cl.getOptionValue(OPTION_OUTPUT_FILE),
                cl.hasOption(OPTION_JSON_FORMAT));
        return;
    }

    Double minSnrThreshold = Double.parseDouble(cl.getOptionValue(OPTION_MIN_SNR_THRESHOLD));
    Double minIntensityThreshold = Double.parseDouble(cl.getOptionValue(OPTION_MIN_INTENSITY_THRESHOLD));
    Double minTimeThreshold = Double.parseDouble(cl.getOptionValue(OPTION_MIN_TIME_THRESHOLD));

    if (cl.hasOption(OPTION_GET_IONS_SUPERSET)) {
        List<IonAnalysisInterchangeModel> models = positiveReplicateResults.stream().map(file -> {
            try {
                return IonAnalysisInterchangeModel.loadIonAnalysisInterchangeModelFromFile(file);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }).collect(Collectors.toList());

        IonAnalysisInterchangeModel transformedModel = IonAnalysisInterchangeModel
                .getSupersetOfIonicVariants(models, minSnrThreshold, minIntensityThreshold, minTimeThreshold);

        printInchisAndIonsToFile(transformedModel, cl.getOptionValue(OPTION_OUTPUT_FILE),
                cl.hasOption(OPTION_JSON_FORMAT));
        return;
    }

    if (cl.hasOption(OPTION_THRESHOLD_ANALYSIS)) {

        if (positiveReplicateResults.size() > 1) {
            LOGGER.error("Since this is a threshold analysis, the number of positive replicates should be 1.");
            System.exit(1);
        }

        // We need to set this variable as a final since it is used in a lambda function below.
        final Set<String> ions = new HashSet<>();
        if (cl.hasOption(OPTION_FILTER_BY_IONS)) {
            ions.addAll(Arrays.asList(cl.getOptionValues(OPTION_FILTER_BY_IONS)));
        }

        HitOrMissSingleSampleFilterAndTransformer hitOrMissSingleSampleTransformer = new HitOrMissSingleSampleFilterAndTransformer(
                minIntensityThreshold, minSnrThreshold, minTimeThreshold, ions);

        IonAnalysisInterchangeModel model = IonAnalysisInterchangeModel.filterAndOperateOnMoleculesFromModel(
                IonAnalysisInterchangeModel.loadIonAnalysisInterchangeModelFromFile(
                        positiveReplicateResults.get(0)),
                hitOrMissSingleSampleTransformer);

        printInchisAndIonsToFile(model, cl.getOptionValue(OPTION_OUTPUT_FILE),
                cl.hasOption(OPTION_JSON_FORMAT));
    }
}

From source file:com.yahoo.yqlplus.example.apis.Programs.java

private static void initProgramMap() {
    programMap = new HashMap<>();
    try {//from   ww w  .  ja va2s. c  om
        compilePrograms();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.travis4j.testing.JsonResources.java

public static JSONObject read(URL resource) {
    try (Scanner scanner = new Scanner(resource.openStream(), "UTF-8").useDelimiter("\\A")) {
        return new JSONObject(scanner.next());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }//from   w  w  w . java 2  s .  com
}

From source file:org.travis4j.testing.JsonResources.java

public static JSONObject read(String name, ClassLoader cl) {
    URL resource = cl.getResource(name);
    if (resource == null) {
        throw new UncheckedIOException(new FileNotFoundException(name));
    }//from   www.  j a  v  a 2 s. c  o  m
    return read(resource);
}

From source file:onl.area51.httpd.action.HttpFunction.java

/**
 * Convert an {@link IOConsumer} into a standard {@link Consumer}.
 * <p>/*from www.j  a v  a  2  s.co  m*/
 * When an {@link IOException} is thrown then an {@link UncheckedIOException} will be thrown instead.
 * <p>
 * @param <V>
 * @param <T>
 * @param c IOConsumer to guard
 * <p>
 * @return consumer
 */
static <V, T> Function<V, T> guard(HttpFunction<V, T> c) {
    return v -> {
        try {
            return c.apply(v);
        } catch (HttpException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new UncheckedIOException(ex);
        }
    };
}

From source file:beyondlambdas.slides.s8_1.Support.java

public static User parseJson(final String json) {
    try {/*from  w w w  .  j a v  a 2  s  .  co  m*/
        final User user = OBJECT_READER.readValue(json);
        System.out.println("Parsed user with id: " + user.id());
        return user;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

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

public static Stream<ZipStreamEntry> stream(Path path) {
    try {/*  w w  w  . j  a  v  a  2s. c om*/
        final InputStream inputStream = Files.newInputStream(path);
        return stream(inputStream).onClose(() -> closeQuietly(inputStream));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.mybatis.spring.boot.autoconfigure.SpringBootVFS.java

private static String preserveSubpackageName(final Resource resource, final String rootPath) {
    try {//from  ww w.  ja v  a  2  s.  com
        final String uriStr = resource.getURI().toString();
        final int start = uriStr.indexOf(rootPath);
        return uriStr.substring(start);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:twg2.dependency.test.PackageJsonTest.java

public static final PackageJson loadPackage1() throws JsonProcessingException, IOException {
    try {//from w ww .j  a  v  a 2 s. c o  m
        return new PackageJson().fromJson(Json.getDefaultInst().getObjectMapper()
                .readTree(new ByteArrayInputStream(pkg1Src.getBytes("UTF-8"))));
    } catch (UnsupportedEncodingException e) {
        throw new UncheckedIOException(e);
    }
}