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);
}
}
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);
}
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);
}
}
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);
}
}
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();
}
}
Aggregations