Search in sources :

Example 26 with UncheckedIOException

use of java.io.UncheckedIOException in project gatk-protected by broadinstitute.

the class XHMMSegmentCallerBaseIntegrationTest method writeChainInTempFile.

public static File writeChainInTempFile(final XHMMData chain) {
    final File result = createTempFile("chain-", ".tab");
    //final File result = new File("/tmp/input");
    final List<String> sampleNames = IntStream.range(0, chain.data.size()).mapToObj(a -> "SAMPLE_" + a).collect(Collectors.toList());
    final List<String> columnNames = new ArrayList<>(sampleNames.size() + 4);
    columnNames.addAll(Arrays.asList(TargetTableColumn.CONTIG.toString(), TargetTableColumn.START.toString(), TargetTableColumn.END.toString(), TargetTableColumn.NAME.toString()));
    columnNames.addAll(sampleNames);
    try (final TableWriter<Integer> writer = new TableWriter<Integer>(result, new TableColumnCollection(columnNames)) {

        @Override
        protected void composeLine(final Integer record, final DataLine dataLine) {
            dataLine.append(chain.targets.get(record).getContig()).append(chain.targets.get(record).getStart()).append(chain.targets.get(record).getEnd()).append(chain.targets.get(record).getName());
            for (final List<Double> sampleData : chain.data) {
                dataLine.append(sampleData.get(record));
            }
        }
    }) {
        writer.writeAllRecords(IntStream.range(0, chain.targets.size()).boxed().collect(Collectors.toList()));
    } catch (final IOException ex) {
        throw new UncheckedIOException(ex);
    }
    return result;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataProvider(org.testng.annotations.DataProvider) org.broadinstitute.hellbender.tools.exome(org.broadinstitute.hellbender.tools.exome) Test(org.testng.annotations.Test) IOException(java.io.IOException) Random(java.util.Random) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) Collectors(java.util.stream.Collectors) File(java.io.File) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) File(java.io.File) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Example 27 with UncheckedIOException

use of java.io.UncheckedIOException in project gatk by broadinstitute.

the class XHMMSegmentCallerBaseIntegrationTest method writeChainInTempFile.

public static File writeChainInTempFile(final XHMMData chain) {
    final File result = createTempFile("chain-", ".tab");
    //final File result = new File("/tmp/input");
    final List<String> sampleNames = IntStream.range(0, chain.data.size()).mapToObj(a -> "SAMPLE_" + a).collect(Collectors.toList());
    final List<String> columnNames = new ArrayList<>(sampleNames.size() + 4);
    columnNames.addAll(Arrays.asList(TargetTableColumn.CONTIG.toString(), TargetTableColumn.START.toString(), TargetTableColumn.END.toString(), TargetTableColumn.NAME.toString()));
    columnNames.addAll(sampleNames);
    try (final TableWriter<Integer> writer = new TableWriter<Integer>(result, new TableColumnCollection(columnNames)) {

        @Override
        protected void composeLine(final Integer record, final DataLine dataLine) {
            dataLine.append(chain.targets.get(record).getContig()).append(chain.targets.get(record).getStart()).append(chain.targets.get(record).getEnd()).append(chain.targets.get(record).getName());
            for (final List<Double> sampleData : chain.data) {
                dataLine.append(sampleData.get(record));
            }
        }
    }) {
        writer.writeAllRecords(IntStream.range(0, chain.targets.size()).boxed().collect(Collectors.toList()));
    } catch (final IOException ex) {
        throw new UncheckedIOException(ex);
    }
    return result;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DataProvider(org.testng.annotations.DataProvider) org.broadinstitute.hellbender.tools.exome(org.broadinstitute.hellbender.tools.exome) Test(org.testng.annotations.Test) IOException(java.io.IOException) Random(java.util.Random) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) Collectors(java.util.stream.Collectors) File(java.io.File) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection) DataLine(org.broadinstitute.hellbender.utils.tsv.DataLine) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TableWriter(org.broadinstitute.hellbender.utils.tsv.TableWriter) File(java.io.File) TableColumnCollection(org.broadinstitute.hellbender.utils.tsv.TableColumnCollection)

Example 28 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 29 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)

Example 30 with UncheckedIOException

use of java.io.UncheckedIOException in project ddf by codice.

the class IngestCommand method buildQueue.

private void buildQueue(File inputFile, ArrayBlockingQueue<Metacard> metacardQueue, long start) {
    try {
        if (includeContent) {
            processIncludeContent(metacardQueue);
        } else {
            try {
                Stream<Path> ingestStream = Files.walk(inputFile.toPath(), FileVisitOption.FOLLOW_LINKS);
                ingestStream.map(Path::toFile).filter(file -> !file.isDirectory()).forEach(file -> addFileToQueue(metacardQueue, start, file));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    } finally {
        phaser.arriveAndDeregister();
    }
}
Also used : Path(java.nio.file.Path) Ansi(org.fusesource.jansi.Ansi) StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) SecurityLogger(ddf.security.common.audit.SecurityLogger) Command(org.apache.karaf.shell.api.action.Command) DirectoryStream(java.nio.file.DirectoryStream) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Path(java.nio.file.Path) InputTransformer(ddf.catalog.transform.InputTransformer) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BlockingQueue(java.util.concurrent.BlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Serializable(java.io.Serializable) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) FileVisitResult(java.nio.file.FileVisitResult) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) StorageException(ddf.catalog.content.StorageException) List(java.util.List) Stream(java.util.stream.Stream) PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) Optional(java.util.Optional) FilenameUtils(org.apache.commons.io.FilenameUtils) IntStream(java.util.stream.IntStream) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) PeriodFormatter(org.joda.time.format.PeriodFormatter) ArrayList(java.util.ArrayList) Reference(org.apache.karaf.shell.api.action.lifecycle.Reference) ContentItem(ddf.catalog.content.data.ContentItem) CreateResponse(ddf.catalog.operation.CreateResponse) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StorageProvider(ddf.catalog.content.StorageProvider) Exceptions(org.codice.ddf.platform.util.Exceptions) ByteSource(com.google.common.io.ByteSource) ExecutorService(java.util.concurrent.ExecutorService) Period(org.joda.time.Period) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) Argument(org.apache.karaf.shell.api.action.Argument) FileInputStream(java.io.FileInputStream) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) Phaser(java.util.concurrent.Phaser) Service(org.apache.karaf.shell.api.action.lifecycle.Service) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade) Option(org.apache.karaf.shell.api.action.Option) InputCollectionTransformer(ddf.catalog.transform.InputCollectionTransformer) InputStream(java.io.InputStream) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)64 IOException (java.io.IOException)60 Path (java.nio.file.Path)12 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 BufferedReader (java.io.BufferedReader)4 URL (java.net.URL)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 Protein (de.bioforscher.jstructure.model.structure.Protein)3 InterruptedIOException (java.io.InterruptedIOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Stream (java.util.stream.Stream)3 ServletException (javax.servlet.ServletException)3