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