Search in sources :

Example 61 with UncheckedIOException

use of java.io.UncheckedIOException in project spf4j by zolyfarkas.

the class DirectStoreAccumulator method recordAt.

@Override
@SuppressFBWarnings("EXS_EXCEPTION_SOFTENING_NO_CHECKED")
public synchronized void recordAt(final long timestampMillis, final long measurement) {
    lastRecordedValue = measurement;
    lastRecordedTS = timestampMillis;
    try {
        measurementStore.saveMeasurements(tableId, timestampMillis, measurement);
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 62 with UncheckedIOException

use of java.io.UncheckedIOException in project spf4j by zolyfarkas.

the class GenericRecordBuilder method generateClasses.

private void generateClasses(final GenericData.StringType st, final Schema... schemas) {
    String[] namespaces = new String[schemas.length];
    for (int i = 0; i < schemas.length; i++) {
        String namespace = schemas[i].getNamespace();
        if (namespace == null) {
            namespace = "";
        }
        namespaces[i] = namespace;
    }
    String commonPrefix = org.spf4j.base.Strings.commonPrefix(namespaces);
    if (commonPrefix.endsWith(".")) {
        commonPrefix = commonPrefix.substring(0, commonPrefix.length() - 1);
    }
    Protocol proto = new Protocol("generated", commonPrefix);
    proto.setTypes(Arrays.asList(schemas));
    SpecificCompiler sc = new SpecificCompiler(proto);
    sc.setStringType(st);
    // use a custom template that does not contain the builder (janino can't compile builder).
    sc.setTemplateDir("org/spf4j/avro/");
    try {
        sc.compileToDestination(null, tmpDir);
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
    try {
        Files.walkFileTree(tmpDir.toPath(), new SetFilesReadOnlyVisitor());
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : SpecificCompiler(org.apache.avro.compiler.specific.SpecificCompiler) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SetFilesReadOnlyVisitor(org.spf4j.io.SetFilesReadOnlyVisitor) Protocol(org.apache.avro.Protocol)

Example 63 with UncheckedIOException

use of java.io.UncheckedIOException in project spf4j by zolyfarkas.

the class CharSequenceTranslator method translate.

@Nullable
public final String translate(@Nullable final CharSequence input) {
    if (input == null) {
        return null;
    }
    try {
        final StringWriter writer = new StringWriter(input.length() * 2);
        translate(input, writer);
        return writer.toString();
    } catch (final IOException ioe) {
        // this should never ever happen while writing to a StringWriter
        throw new UncheckedIOException(ioe);
    }
}
Also used : StringWriter(java.io.StringWriter) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 64 with UncheckedIOException

use of java.io.UncheckedIOException in project spf4j by zolyfarkas.

the class JDiffRunner method writeChangesIndexHtml.

public void writeChangesIndexHtml(final File reportOutputDirectory, final String fileName) throws IOException {
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(reportOutputDirectory.toPath().resolve(fileName)), StandardCharsets.UTF_8))) {
        writer.append("<HTML>\n" + "<HEAD>\n" + "<TITLE>\n" + "API Differences Reports\n" + "</TITLE>\n" + "</HEAD>\n" + "<BODY>\n" + "<table summary=\"Api Difference Reports\"" + " width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
        Path reportPath = reportOutputDirectory.toPath();
        Files.walk(reportPath, 2).map((p) -> reportPath.relativize(p)).filter((p) -> p.getNameCount() > 1 && p.endsWith("changes.html")).forEach((p) -> {
            try {
                writer.append("  <tr>\n" + "  <td bgcolor=\"#FFFFCC\">\n" + "    <font size=\"+1\"><a href=\"" + p + "\"> " + p.getName(0).toString().replace("_", " to ") + " </a></font>\n" + "  </td>\n" + "  </tr>");
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        });
        writer.append("</TABLE>\n" + "</BODY>\n" + "</HTML>");
    }
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) ToolchainManager(org.apache.maven.toolchain.ToolchainManager) Version(org.eclipse.aether.version.Version) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) TreeSet(java.util.TreeSet) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) Artifact(org.apache.maven.artifact.Artifact) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MavenSession(org.apache.maven.execution.MavenSession) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Collection(java.util.Collection) MojoExecution(org.apache.maven.plugin.MojoExecution) Set(java.util.Set) IOException(java.io.IOException) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) MavenRepositoryUtils(org.spf4j.maven.MavenRepositoryUtils) List(java.util.List) FileUtils(org.codehaus.plexus.util.FileUtils) Compress(org.spf4j.jdiff.utils.Compress) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) RepositorySystem(org.eclipse.aether.RepositorySystem) OutputStreamWriter(java.io.OutputStreamWriter) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BufferedWriter(java.io.BufferedWriter)

Example 65 with UncheckedIOException

use of java.io.UncheckedIOException in project herddb by diennea.

the class BLink method toStringFull.

/**
 * Build a full string representation of this tree.
 * <p>
 * <b>Pay attention:</b> it will load/unload nodes potentially polluting the page replacement policy. Use
 * this method just for test and analysis purposes.
 * </p>
 *
 * @return full tree string representation
 */
@SuppressWarnings("unchecked")
public String toStringFull() {
    Node<K, V> top = anchor.top;
    Deque<Object[]> stack = new LinkedList<>();
    Set<Node<K, V>> seen = new HashSet<>();
    stack.push(new Object[] { top, 0 });
    int indents;
    try {
        StringBuilder builder = new StringBuilder();
        while (!stack.isEmpty()) {
            Object[] el = stack.pop();
            Node<K, V> node = (Node<K, V>) el[0];
            indents = (int) el[1];
            for (int i = 0; i < indents; ++i) {
                builder.append("-");
            }
            builder.append("> ");
            if (seen.contains(node)) {
                builder.append("Seen: ").append(node.pageId).append('\n');
            } else {
                seen.add(node);
                builder.append(node).append(' ');
                if (node.leaf) {
                    Deque<Object[]> cstack = new LinkedList<>();
                    /* No other nodes currently loaded and can't require to unload itself */
                    final LockAndUnload<K, V> loadLock = node.loadAndLock(true);
                    try {
                        for (Entry<Comparable<K>, V> child : (Collection<Entry<Comparable<K>, V>>) (Collection<?>) node.map.entrySet()) {
                            builder.append(child.getValue()).append(" <- ").append(child.getKey()).append(" | ");
                        }
                        builder.setLength(builder.length() - 3);
                    } finally {
                        loadLock.unlock();
                        if (loadLock.unload != null)
                            loadLock.unload();
                    }
                    while (!cstack.isEmpty()) {
                        stack.push(cstack.pop());
                    }
                } else {
                    Deque<Object[]> cstack = new LinkedList<>();
                    /* No other nodes currently loaded and can't require to unload itself */
                    final LockAndUnload<K, V> loadLock = node.loadAndLock(true);
                    try {
                        for (Entry<Comparable<K>, Node<K, V>> child : (Collection<Entry<Comparable<K>, Node<K, V>>>) (Collection<?>) node.map.entrySet()) {
                            builder.append(child.getValue().pageId).append(" <- ").append(child.getKey()).append(" | ");
                            cstack.push(new Object[] { child.getValue(), indents + 1 });
                        }
                        builder.setLength(builder.length() - 3);
                    } finally {
                        loadLock.unlock();
                        if (loadLock.unload != null)
                            loadLock.unload();
                    }
                    while (!cstack.isEmpty()) {
                        stack.push(cstack.pop());
                    }
                }
                builder.append('\n');
            }
        }
        return builder.toString();
    } catch (IOException ex) {
        throw new UncheckedIOException("failed to generate full string representation", ex);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) LinkedList(java.util.LinkedList) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)826 IOException (java.io.IOException)786 File (java.io.File)109 Path (java.nio.file.Path)106 ArrayList (java.util.ArrayList)70 InputStream (java.io.InputStream)58 Map (java.util.Map)58 List (java.util.List)55 HashMap (java.util.HashMap)44 Test (org.junit.Test)38 Files (java.nio.file.Files)37 Collectors (java.util.stream.Collectors)37 Stream (java.util.stream.Stream)31 URL (java.net.URL)29 StringWriter (java.io.StringWriter)27 CursorContext (org.neo4j.io.pagecache.context.CursorContext)25 FileInputStream (java.io.FileInputStream)23 HashSet (java.util.HashSet)23 PageCursor (org.neo4j.io.pagecache.PageCursor)22 Optional (java.util.Optional)21