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:com.github.anba.es6draft.v8.MiniJSUnitTest.java

private static boolean containsNativeSyntax(Path p) {
    try {/*from w ww.  j a va 2 s  . com*/
        String content = new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
        return content.indexOf('%') != -1;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.apache.geode.internal.process.AbstractProcessStreamReaderIntegrationTest.java

protected void givenStartedProcessWithStreamListeners(final Class<?> mainClass) {
    try {/*  www  .  j a v a2 s.  com*/
        process = new ProcessBuilder(createCommandLine(mainClass)).start();
        stdout = buildProcessStreamReader(process.getInputStream(), getReadingMode(), stdoutBuffer);
        stderr = buildProcessStreamReader(process.getErrorStream(), getReadingMode(), stderrBuffer);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:am.ik.categolj3.api.git.GitStore.java

void syncHead() {
    log.info("Syncing HEAD...");

    ObjectId oldHead = this.currentHead.get();
    ObjectId newHead = this.head();

    try (Repository repository = this.git.getRepository()) {
        DiffFormatter diffFormatter = new DiffFormatter(System.out);
        diffFormatter.setRepository(repository);
        RevWalk walk = new RevWalk(repository);
        try {/* w ww. jav  a2s  .  co  m*/
            RevCommit fromCommit = walk.parseCommit(oldHead);
            RevCommit toCommit = walk.parseCommit(newHead);
            List<DiffEntry> list = diffFormatter.scan(fromCommit.getTree(), toCommit.getTree());

            list.forEach(diff -> {
                log.info("[{}]\tnew={}\told={}", diff.getChangeType(), diff.getNewPath(), diff.getOldPath());
                if (diff.getOldPath() != null) {
                    Path path = Paths
                            .get(gitProperties.getBaseDir().getAbsolutePath() + "/" + diff.getOldPath());
                    if (Entry.isPublic(path)) {
                        Long entryId = Entry.parseEntryId(path);
                        log.info("evict Entry({})", entryId);
                        this.entryCache.evict(entryId);
                    }
                }
                if (diff.getNewPath() != null) {
                    Path path = Paths
                            .get(gitProperties.getBaseDir().getAbsolutePath() + "/" + diff.getNewPath());
                    this.loadEntry(path).ifPresent(entry -> {
                        log.info("put Entry({})", entry.getEntryId());
                        this.entryCache.put(entry.getEntryId(), entry);
                    });
                }
            });
        } finally {
            walk.dispose();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

    this.currentHead.set(newHead);
}

From source file:org.lightjason.agentspeak.common.CCommon.java

/**
 * get all classes within an Java package as action
 *
 * @param p_package full-qualified package name or empty for default package
 * @return action stream//from  www.j a  va2  s .c  o  m
 */
@SuppressWarnings("unchecked")
public static Stream<IAction> actionsFromPackage(final String... p_package) {
    return ((p_package == null) || (p_package.length == 0)
            ? Stream.of(MessageFormat.format("{0}.{1}", PACKAGEROOT, "action.buildin"))
            : Arrays.stream(p_package)).flatMap(j -> {
                try {
                    return ClassPath.from(Thread.currentThread().getContextClassLoader())
                            .getTopLevelClassesRecursive(j).parallelStream().map(ClassPath.ClassInfo::load)
                            .filter(i -> !Modifier.isAbstract(i.getModifiers()))
                            .filter(i -> !Modifier.isInterface(i.getModifiers()))
                            .filter(i -> Modifier.isPublic(i.getModifiers()))
                            .filter(IAction.class::isAssignableFrom).map(i -> {
                                try {
                                    return (IAction) i.newInstance();
                                } catch (final IllegalAccessException | InstantiationException l_exception) {
                                    LOGGER.warning(CCommon.languagestring(CCommon.class, "actioninstantiate", i,
                                            l_exception));
                                    return null;
                                }
                            })

                            // action can be instantiate
                            .filter(Objects::nonNull)

                            // check usable action name
                            .filter(CCommon::actionusable);
                } catch (final IOException l_exception) {
                    throw new UncheckedIOException(l_exception);
                }
            });
}

From source file:com.mgmtp.perfload.perfalyzer.util.IoUtilities.java

public static void writeToChannel(final WritableByteChannel destChannel, final ByteBuffer buffer) {
    try {//from  w  ww .  j ava 2s.  co m
        // write to the destination channel
        destChannel.write(buffer);

        // If partial transfer, shift remainder down so it does not get lost
        // If buffer is empty, this is the same as calling clear()
        buffer.compact();

        // EOF will leave buffer in fill state
        buffer.flip();

        // make sure the buffer is fully drained
        while (buffer.hasRemaining()) {
            destChannel.write(buffer);
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}

From source file:org.apache.geode.internal.process.ControllableProcess.java

private void deleteFiles(final File directory, final ProcessType processType) {
    try {//www. ja v  a2  s.co m
        deleteFileWithValidation(new File(directory, processType.getStatusRequestFileName()),
                "statusRequestFile");
        deleteFileWithValidation(new File(directory, processType.getStatusFileName()), "statusFile");
        deleteFileWithValidation(new File(directory, processType.getStopRequestFileName()), "stopRequestFile");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.apache.bookkeeper.tools.perf.dlog.PerfSegmentReader.java

void readSegmentSplit(Split split) throws Exception {
    LogSegmentEntryReader reader = result(split.manager.getNamespaceDriver()
            .getLogSegmentEntryStore(Role.READER).openReader(split.segment, split.getStartEntryId()));
    reader.start();//w w  w.  ja v  a  2s .co m

    try {
        MutableBoolean isDone = new MutableBoolean(false);
        while (!isDone.booleanValue()) {
            // 100 is just an indicator
            List<Entry.Reader> entries = result(reader.readNext(100));
            entries.forEach(entry -> {
                LogRecordWithDLSN record;
                try {
                    while ((record = entry.nextRecord()) != null) {
                        recordsRead.increment();
                        bytesRead.add(record.getPayloadBuf().readableBytes());
                    }
                } catch (IOException ioe) {
                    throw new UncheckedIOException(ioe);
                } finally {
                    entry.release();
                }
                if (split.getEndEntryId() >= 0 && entry.getEntryId() >= split.getEndEntryId()) {
                    isDone.setValue(true);
                }
            });
        }
    } catch (EndOfLogSegmentException e) {
        // we reached end of log segment
        return;
    } finally {
        reader.asyncClose();
    }

}

From source file:org.everit.json.schema.IssueTest.java

private Object loadJsonFile(final File file) {

    Object subject = null;//from   ww  w.j  av a2 s  .  c  om

    try {
        JSONTokener jsonTok = new JSONTokener(new FileInputStream(file));

        // Determine if we have a single JSON object or an array of them
        Object jsonTest = jsonTok.nextValue();
        if (jsonTest instanceof JSONObject) {
            // The message contains a single JSON object
            subject = jsonTest;
        } else if (jsonTest instanceof JSONArray) {
            // The message contains a JSON array
            subject = jsonTest;
        }
    } catch (JSONException e) {
        throw new RuntimeException("failed to parse subject json file", e);
    } catch (FileNotFoundException e) {
        throw new UncheckedIOException(e);
    }
    return subject;
}

From source file:org.trellisldp.rosid.file.FileResourceService.java

@Override
public Stream<IRI> tryPurge(final IRI identifier) {
    final List<IRI> binaries = new ArrayList<>();
    final File directory = resourceDirectory(partitions, identifier);

    try (final Stream<String> lineStream = lines(new File(directory, RESOURCE_JOURNAL).toPath())) {
        lineStream.flatMap(line -> {/*w w  w  .  ja v a 2  s. c  o m*/
            final String[] parts = line.split(" ", 6);
            if (parts.length == 6 && parts[0].equals("A") && parts[1].equals(identifier.toString())
                    && parts[2].equals(DC.hasPart.toString())
                    && parts[4].equals(Trellis.PreferServerManaged.toString())) {
                return of(parts[3]);
            }
            return empty();
        }).map(iri -> iri.substring(1, iri.length() - 1)).map(rdf::createIRI).forEach(binaries::add);
    } catch (final IOException ex) {
        LOGGER.error("Error processing journal file: {}", ex.getMessage());
        throw new UncheckedIOException(ex);
    }

    try {
        deleteIfExists(new File(directory, RESOURCE_CACHE).toPath());
        deleteIfExists(new File(directory, RESOURCE_QUADS).toPath());
        // Truncate history file, rather than actually deleting it
        try (final BufferedWriter writer = newBufferedWriter(new File(directory, RESOURCE_JOURNAL).toPath(),
                UTF_8, WRITE, TRUNCATE_EXISTING)) {
            writer.write("");
        }
    } catch (final IOException ex) {
        LOGGER.error("Error deleting files: {}", ex.getMessage());
        throw new UncheckedIOException(ex);
    }

    return binaries.stream();
}

From source file:org.eclipse.che.selenium.core.client.TestGitHubRepository.java

/**
 * Copies content of directory {@code pathToRootContentDirectory} to the specified branch in the
 * GitHub repository. It tries to recreate the file ones again in case of FileNotFoundException
 * occurs./*from ww  w .ja  v  a  2  s .com*/
 *
 * @param pathToRootContentDirectory path to the directory with content
 * @param branch name of the target branch
 * @throws IOException
 */
public void addContent(Path pathToRootContentDirectory, String branch) throws IOException {
    Files.walk(pathToRootContentDirectory).filter(Files::isRegularFile).forEach(pathToFile -> {
        try {
            createFile(pathToRootContentDirectory, pathToFile, branch);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    });
}