use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class BinaryObserver method apply.
@Override
public Subscriber<? super String> apply(Subscriber<? super Binary> outgoing) {
return new Subscriber<String>() {
@Override
public void onComplete() {
try {
w.flush();
w.close();
fos.flush();
fos.close();
Binary binary;
if (NavajoFactory.getInstance().isSandboxMode()) {
binary = new Binary(BinaryObserver.this.inMemory);
} else {
binary = new Binary(dataFile, true);
}
binary.setDigest(digest);
outgoing.onNext(binary);
outgoing.onComplete();
} catch (Throwable e) {
outgoing.onError(e);
}
}
@Override
public void onError(Throwable t) {
// propagate
outgoing.onError(t);
}
@Override
public void onNext(String line) {
count++;
try {
w.write(line);
} catch (IOException e) {
outgoing.onError(e);
}
}
@Override
public void onSubscribe(Subscription s) {
}
};
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class StreamDocument method gatherBinary.
public static FlowableOperator<Binary, String> gatherBinary() {
return new BaseFlowableOperator<Binary, String>(1) {
@Override
public Subscriber<? super String> apply(Subscriber<? super Binary> child) throws Exception {
return new Subscriber<String>() {
Binary result = null;
@Override
public void onComplete() {
if (result != null) {
try {
result.finishPushContent();
operatorNext("", r -> result, child);
} catch (IOException e) {
operatorError(e, child);
}
}
operatorComplete(child);
}
@Override
public void onError(Throwable t) {
operatorError(t, child);
}
@Override
public void onNext(String e) {
try {
result.pushContent(e);
operatorRequest(1);
} catch (IOException ex) {
operatorError(ex, child);
}
}
@Override
public void onSubscribe(Subscription s) {
operatorSubscribe(s, child);
result = createBinary();
}
private Binary createBinary() {
Binary result = new Binary();
try {
result.startPushRead();
} catch (IOException e1) {
logger.error("Error: ", e1);
}
return result;
}
};
}
};
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class StreamDocument method createBinary.
public static ObservableOperator<Binary, byte[]> createBinary() {
return new ObservableOperator<Binary, byte[]>() {
@Override
public Observer<? super byte[]> apply(Observer<? super Binary> out) throws Exception {
Binary result = new Binary();
result.startBinaryPush();
return new Observer<byte[]>() {
@Override
public void onComplete() {
try {
result.finishPushContent();
} catch (IOException e) {
e.printStackTrace();
out.onError(e);
return;
}
out.onNext(result);
out.onComplete();
}
@Override
public void onError(Throwable e) {
out.onError(e);
}
@Override
public void onNext(byte[] b) {
result.pushContent(b);
}
@Override
public void onSubscribe(Disposable d) {
out.onSubscribe(new Disposable() {
private boolean disposed = false;
@Override
public void dispose() {
disposed = true;
}
@Override
public boolean isDisposed() {
return disposed;
}
});
}
};
}
};
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class Prop method write.
public void write(Writer sw, int indent) throws IOException {
for (int a = 0; a < indent; a++) {
sw.write(" ");
}
sw.write("<property");
if (name != null) {
sw.write(" name=\"" + StringEscapeUtils.escapeXml(name) + "\"");
}
if (type != null) {
sw.write(" type=\"" + type + "\"");
}
if (value != null && !isBinary()) {
String value = valueAsString();
String escapedValue = StringEscapeUtils.escapeXml(value);
sw.write(" value=\"" + escapedValue + "\"");
}
if (direction != null && direction.isPresent()) {
sw.write(" direction=\"" + direction().get() + "\"");
}
if (description != null && !"".equals(description)) {
sw.write(" description=\"" + description + "\"");
}
if (cardinality != null && cardinality.isPresent() && !"".equals(cardinality.get())) {
sw.write(" cardinality=\"" + cardinality.get() + "\"");
}
if (length > 0) {
sw.write(" length=\"" + length + "\"");
}
if (!isBinary() && (selections == null || selections.isEmpty())) {
sw.write("/>\n");
} else {
sw.write(">\n");
if (isBinary()) {
Binary b = binary;
b.writeBase64(sw);
} else {
for (Select select : selections) {
writeSelection(sw, select, indent + NavajoStreamSerializer.INDENT);
}
}
for (int a = 0; a < indent; a++) {
sw.write(" ");
}
sw.write("</property>\n");
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinaries method testGatherBinary.
@Test
public void testGatherBinary() throws Exception {
Binary nn = Bytes.from(TestRx.class.getClassLoader().getResourceAsStream("tml_with_binary.xml"), 4096).lift(XML.parseFlowable(5)).flatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).lift(StreamDocument.observeBinary("SecureImage/Image")).lift(StreamDocument.gatherBinary()).doOnNext(e -> System.err.println("Event: " + e)).blockingFirst();
System.err.println("eventcount: " + nn.getLength());
// nn.write(System.err);
// System.err.println("RESULT:\n"+new String(baos.toByteArray()));
Assert.assertTrue(nn.getLength() == 3245);
}
Aggregations