Search in sources :

Example 21 with UncheckedIOException

use of java.io.UncheckedIOException in project jstructure by JonStargaryen.

the class SimpleEnergyProfileRunner method main.

public static void main(String... args) {
    if (args.length != 1 && args.length != 2) {
        // print usage
        System.err.println("usage: java -jar energy.jar /path/to/file.pdb [/path/to/output/file/if/desired.ep]");
        throw new IllegalArgumentException("too " + (args.length < 1 ? "few" : "many") + " arguments provided");
    }
    String inputPath = args[0];
    boolean outputRequested = false;
    String outputPath = null;
    if (args.length == 2) {
        outputRequested = true;
        outputPath = args[1];
    }
    logger.info("computing energy profile for {}", inputPath);
    logger.info("writing output to {}", outputRequested ? outputPath : "console");
    try {
        // read and parse protein
        Protein protein = ProteinParser.source(Paths.get(inputPath)).parse();
        // calculate energy profile
        featureProvider.process(protein);
        // compose output
        String output = AdvancedEnergyProfileRunner.composeOutput(protein);
        if (outputRequested) {
            Files.write(Paths.get(outputPath), output.getBytes());
        } else {
            System.out.println(output);
        }
    } catch (UncheckedIOException e) {
        System.err.println("failed to parse PDB file located at " + inputPath);
        throw e;
    } catch (IOException e) {
        System.err.println("writing the output file failed - destination " + outputPath);
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Protein(de.bioforscher.jstructure.model.structure.Protein)

Example 22 with UncheckedIOException

use of java.io.UncheckedIOException in project intellij-community by JetBrains.

the class PsiElementConcatenationInspectionTest method beforeActionStarted.

@Override
protected void beforeActionStarted(String testName, String contents) {
    try {
        createAndSaveFile("com/intellij/psi/PsiElement.java", "package com.intellij.psi;interface PsiElement {}");
        createAndSaveFile("com/intellij/psi/PsiExpression.java", "package com.intellij.psi;interface PsiExpression extends PsiElement {}");
        createAndSaveFile("com/intellij/psi/PsiType.java", "package com.intellij.psi;interface PsiType {}");
        createAndSaveFile("com/intellij/psi/PsiElementFactory.java", "package com.intellij.psi;\n" + "interface PsiElementFactory {\n" + "PsiExpression createExpressionFromText(String str, PsiElement context);\n" + "}");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    super.beforeActionStarted(testName, contents);
}
Also used : UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 23 with UncheckedIOException

use of java.io.UncheckedIOException in project karaf by apache.

the class BundleWires method delete.

void delete(Path path) {
    try {
        Files.createDirectories(path);
        Path file = path.resolve(Long.toString(this.bundleId));
        Files.deleteIfExists(file);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 24 with UncheckedIOException

use of java.io.UncheckedIOException in project jgnash by ccavanaugh.

the class FXMLUtils method load.

/**
     * Creates a new Stage with application defaults {@code StageStyle.DECORATED}, {@code Modality.APPLICATION_MODAL}
     * with the specified fxml {@code URL} as the {@code Scene}.  The default resource bundle is used.
     *
     * @param fxmlUrl the fxml {@code URL}
     * @param title the Stage title
     * @param <C> the fxml controller type
     * @return Pair containing the Stage and controller
     */
public static <C> Pair<C> load(@NotNull final URL fxmlUrl, final String title) {
    final FXMLLoader fxmlLoader = new FXMLLoader(fxmlUrl, ResourceUtils.getBundle());
    final Stage stage = new Stage(StageStyle.DECORATED);
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.initOwner(MainView.getPrimaryStage());
    try {
        final Scene scene = new Scene(fxmlLoader.load());
        scene.getStylesheets().addAll(MainView.DEFAULT_CSS);
        scene.getRoot().styleProperty().bind(ThemeManager.styleProperty());
        final C controller = fxmlLoader.getController();
        stage.setScene(scene);
        stage.getIcons().add(StaticUIMethods.getApplicationIcon());
        stage.setTitle(title);
        // force a resize, some stages need a push
        stage.sizeToScene();
        // Inject the scene into the controller
        injectParent(controller, scene);
        stage.setOnShown(event -> Platform.runLater(() -> {
            stage.sizeToScene();
            stage.setMinHeight(stage.getHeight());
            stage.setMinWidth(stage.getWidth());
        }));
        return new Pair<>(controller, stage);
    } catch (final IOException ioe) {
        // log and throw an unchecked exception
        Logger.getLogger(FXMLUtils.class.getName()).log(Level.SEVERE, ioe.getMessage(), ioe);
        throw new UncheckedIOException(ioe);
    }
}
Also used : Stage(javafx.stage.Stage) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader)

Example 25 with UncheckedIOException

use of java.io.UncheckedIOException in project chuidiang-ejemplos by chuidiang.

the class WriteFile method writeWithFilesAndStream.

private static void writeWithFilesAndStream() {
    String[] lines = new String[] { "line 1", "line 2", "line 2" };
    Path path = Paths.get("outputfile.txt");
    try (BufferedWriter br = Files.newBufferedWriter(path, Charset.defaultCharset(), StandardOpenOption.CREATE)) {
        Arrays.stream(lines).forEach((s) -> {
            try {
                br.write(s);
                br.newLine();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)76 IOException (java.io.IOException)72 Path (java.nio.file.Path)13 InputStream (java.io.InputStream)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 File (java.io.File)6 Arrays (java.util.Arrays)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 BufferedReader (java.io.BufferedReader)4 URL (java.net.URL)4 IntStream (java.util.stream.IntStream)4 Protein (de.bioforscher.jstructure.model.structure.Protein)3 InterruptedIOException (java.io.InterruptedIOException)3 Random (java.util.Random)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3