use of org.apache.tools.ant.util.ReaderInputStream in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors.
private ErrorsAndDMNModelAsSerialized roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors(InputStream dmnXmlInputStream) throws IOException {
String xml = null;
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(dmnXmlInputStream))) {
xml = buffer.lines().collect(Collectors.joining("\n"));
} catch (Exception e) {
throw new RuntimeException("test utility method roundTripUnmarshalMarshalThenUnmarshalDMN failed to read XML content.", e);
}
LOG.debug("ORIGINAL xml:\n{}\n", xml);
final List<Message> messages0 = kieBuilderMessagesUsingDMNXML(xml);
assertTrue("The DMN XML content did NOT result in compilation errors and this test method expected errors to be detected. If this was intentional use test method roundTripUnmarshalMarshalThenUnmarshalDMN", messages0.stream().filter(m -> m.getLevel().equals(Message.Level.ERROR)).count() > 0);
DMNMarshallerStandalone m = getDMNMarshaller();
// first unmarshal from DMN XML to Stunner DMN Graph
@SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), new ReaderInputStream(new StringReader(xml)));
// round trip to Stunner DMN Graph back to DMN XML
DiagramImpl diagram = createDiagram();
diagram.setGraph(g);
String mString = m.marshall(diagram);
LOG.debug("MARSHALLED ROUNDTRIP RESULTING xml:\n{}\n", mString);
// now unmarshal once more, from the marshalled just done above, into a DMNRuntime
final List<Message> result = kieBuilderMessagesUsingDMNXML(mString);
assertTrue("The DMN XML content did NOT result in compilation errors and this test method expected errors to be detected. If this was intentional use test method roundTripUnmarshalMarshalThenUnmarshalDMN", messages0.stream().filter(msg -> msg.getLevel().equals(Message.Level.ERROR)).count() > 0);
Definitions definitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(mString);
return new ErrorsAndDMNModelAsSerialized(result, definitions);
}
use of org.apache.tools.ant.util.ReaderInputStream in project intellij-community by JetBrains.
the class GradleResourceFileProcessor method transform.
private static InputStream transform(List<ResourceRootFilter> filters, FileInputStream original, Ref<File> outputFileRef, CompileContext context) {
final InputStreamReader streamReader = new InputStreamReader(original);
final Reader newReader = new ChainingFilterTransformer(context, filters, outputFileRef).transform(streamReader);
return streamReader == newReader ? original : new ReaderInputStream(newReader);
}
use of org.apache.tools.ant.util.ReaderInputStream in project ant by apache.
the class Redirector method createStreams.
/**
* Create the input, error and output streams based on the configuration
* options.
*/
public void createStreams() {
synchronized (outMutex) {
outStreams();
if (alwaysLogOut || outputStream == null) {
final OutputStream outputLog = new LogOutputStream(managingTask, Project.MSG_INFO);
outputStream = (outputStream == null) ? outputLog : new TeeOutputStream(outputLog, outputStream);
}
if ((outputFilterChains != null && outputFilterChains.size() > 0) || !(outputEncoding.equalsIgnoreCase(inputEncoding))) {
try {
final LeadPipeInputStream snk = new LeadPipeInputStream();
snk.setManagingComponent(managingTask);
InputStream outPumpIn = snk;
Reader reader = new InputStreamReader(outPumpIn, inputEncoding);
if (outputFilterChains != null && outputFilterChains.size() > 0) {
final ChainReaderHelper helper = new ChainReaderHelper();
helper.setProject(managingTask.getProject());
helper.setPrimaryReader(reader);
helper.setFilterChains(outputFilterChains);
reader = helper.getAssembledReader();
}
outPumpIn = new ReaderInputStream(reader, outputEncoding);
final Thread t = new Thread(threadGroup, new StreamPumper(outPumpIn, outputStream, true), "output pumper");
t.setPriority(Thread.MAX_PRIORITY);
outputStream = new PipedOutputStream(snk);
t.start();
} catch (final IOException eyeOhEx) {
throw new BuildException("error setting up output stream", eyeOhEx);
}
}
}
synchronized (errMutex) {
errorStreams();
if (alwaysLogErr || errorStream == null) {
final OutputStream errorLog = new LogOutputStream(managingTask, Project.MSG_WARN);
errorStream = (errorStream == null) ? errorLog : new TeeOutputStream(errorLog, errorStream);
}
if ((errorFilterChains != null && errorFilterChains.size() > 0) || !(errorEncoding.equalsIgnoreCase(inputEncoding))) {
try {
final LeadPipeInputStream snk = new LeadPipeInputStream();
snk.setManagingComponent(managingTask);
InputStream errPumpIn = snk;
Reader reader = new InputStreamReader(errPumpIn, inputEncoding);
if (errorFilterChains != null && errorFilterChains.size() > 0) {
final ChainReaderHelper helper = new ChainReaderHelper();
helper.setProject(managingTask.getProject());
helper.setPrimaryReader(reader);
helper.setFilterChains(errorFilterChains);
reader = helper.getAssembledReader();
}
errPumpIn = new ReaderInputStream(reader, errorEncoding);
final Thread t = new Thread(threadGroup, new StreamPumper(errPumpIn, errorStream, true), "error pumper");
t.setPriority(Thread.MAX_PRIORITY);
errorStream = new PipedOutputStream(snk);
t.start();
} catch (final IOException eyeOhEx) {
throw new BuildException("error setting up error stream", eyeOhEx);
}
}
}
synchronized (inMutex) {
// whatever warnings are needed
if (input != null && input.length > 0) {
managingTask.log("Redirecting input from file" + ((input.length == 1) ? "" : "s"), Project.MSG_VERBOSE);
try {
inputStream = new ConcatFileInputStream(input);
} catch (final IOException eyeOhEx) {
throw new BuildException(eyeOhEx);
}
((ConcatFileInputStream) inputStream).setManagingComponent(managingTask);
} else if (inputString != null) {
final StringBuffer buf = new StringBuffer("Using input ");
if (logInputString) {
buf.append('"').append(inputString).append('"');
} else {
buf.append("string");
}
managingTask.log(buf.toString(), Project.MSG_VERBOSE);
inputStream = new ByteArrayInputStream(inputString.getBytes());
}
if (inputStream != null && inputFilterChains != null && inputFilterChains.size() > 0) {
final ChainReaderHelper helper = new ChainReaderHelper();
helper.setProject(managingTask.getProject());
try {
helper.setPrimaryReader(new InputStreamReader(inputStream, inputEncoding));
} catch (final IOException eyeOhEx) {
throw new BuildException("error setting up input stream", eyeOhEx);
}
helper.setFilterChains(inputFilterChains);
inputStream = new ReaderInputStream(helper.getAssembledReader(), inputEncoding);
}
}
}
use of org.apache.tools.ant.util.ReaderInputStream in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_decisionservice2_1outputDecision1encapsulatedDecision.
@Test
public void test_decisionservice2_1outputDecision1encapsulatedDecision() throws IOException {
final DMNMarshallerStandalone m = getDMNMarshaller();
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/DROOLS-3372bis.dmn"));
Node<?, ?> nodeDS = g.getNode("_659a06e2-ae80-496c-8783-f790a640bb49");
Node<?, ?> nodeDecisionPostfix = g.getNode("_3a69915a-30af-4de3-a07f-6be514f53caa");
Node<?, ?> nodeDecisionPrefix = g.getNode("_afce4fb3-9a7c-4791-bbfe-63d4b76bd61a");
moveNode(nodeDecisionPostfix, 0, -280);
makeNodeChildOf(nodeDecisionPostfix, nodeDS);
moveNode(nodeDecisionPrefix, 0, -170);
makeNodeChildOf(nodeDecisionPrefix, nodeDS);
DiagramImpl diagram = createDiagram();
diagram.setGraph(g);
String mString = m.marshall(diagram);
LOG.debug("MARSHALLED ROUNDTRIP RESULTING xml:\n{}\n", mString);
roundTripUnmarshalThenMarshalUnmarshal(new ReaderInputStream(new StringReader(mString)), this::check_decisionservice2_1outputDecision1encapsulatedDecision);
}
use of org.apache.tools.ant.util.ReaderInputStream in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_decisionservice_1outputDecision.
@Test
public void test_decisionservice_1outputDecision() throws IOException {
final DMNMarshallerStandalone m = getDMNMarshaller();
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/DROOLS-3372.dmn"));
Node<?, ?> nodeDS = g.getNode("_659a06e2-ae80-496c-8783-f790a640bb49");
Node<?, ?> nodeDecisionPostfix = g.getNode("_3a69915a-30af-4de3-a07f-6be514f53caa");
moveNode(nodeDecisionPostfix, 0, -280);
makeNodeChildOf(nodeDecisionPostfix, nodeDS);
DiagramImpl diagram = createDiagram();
diagram.setGraph(g);
String mString = m.marshall(diagram);
LOG.debug("MARSHALLED ROUNDTRIP RESULTING xml:\n{}\n", mString);
roundTripUnmarshalThenMarshalUnmarshal(new ReaderInputStream(new StringReader(mString)), this::check_decisionservice_1outputDecision);
}
Aggregations