use of java.io.PipedInputStream in project jetty.project by eclipse.
the class WarURLConnection method substitueManifest.
/**
* Use PipedOuputStream and PipedInputStream to do the transformation without making
* a new temporary file ust to replace the manifest.
* @param newmanifest The new manifest
* @param rawIn The file input stream or equivalent. not the jar input stream.
*/
public static InputStream substitueManifest(final Manifest newmanifest, final InputStream rawIn) throws IOException {
final PipedOutputStream pOut = new PipedOutputStream();
PipedInputStream pIn = new PipedInputStream(pOut);
Runnable run = new Runnable() {
public void run() {
JarInputStream jin = null;
JarOutputStream dest = null;
try {
jin = new JarInputStream(rawIn, false);
dest = new JarOutputStream(pOut, newmanifest);
ZipEntry next = jin.getNextEntry();
while (next != null) {
if (next.getName().equalsIgnoreCase(JarFile.MANIFEST_NAME)) {
continue;
}
dest.putNextEntry(next);
if (next.getSize() > 0) {
IO.copy(jin, dest, next.getSize());
}
next = jin.getNextJarEntry();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (dest != null)
IO.close(dest);
if (jin != null)
IO.close(jin);
IO.close(pOut);
}
}
};
Thread th = new Thread(run);
th.start();
return pIn;
}
use of java.io.PipedInputStream in project jetty.project by eclipse.
the class ReadLineInputStreamTest method before.
@Before
public void before() throws Exception {
_queue.clear();
_pin = new PipedInputStream();
_pout = new PipedOutputStream(_pin);
_in = new ReadLineInputStream(_pin);
_writer = new Thread() {
@Override
public void run() {
try {
OutputStream out = _pout;
while (out != null) {
String s = _queue.poll(100, TimeUnit.MILLISECONDS);
if (s != null) {
if ("__CLOSE__".equals(s))
_pout.close();
else {
_pout.write(s.getBytes(StandardCharsets.UTF_8));
Thread.sleep(50);
}
}
out = _pout;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
_writer = null;
}
}
};
_writer.start();
}
use of java.io.PipedInputStream in project hadoop by apache.
the class TestTools method checkOutput.
private void checkOutput(String[] args, String pattern, PrintStream out, Class<?> clazz) {
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
PrintStream oldOut = System.out;
PrintStream oldErr = System.err;
try {
PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut, PIPE_BUFFER_SIZE);
if (out == System.out) {
System.setOut(new PrintStream(pipeOut));
} else if (out == System.err) {
System.setErr(new PrintStream(pipeOut));
}
if (clazz == DelegationTokenFetcher.class) {
expectDelegationTokenFetcherExit(args);
} else if (clazz == JMXGet.class) {
expectJMXGetExit(args);
} else if (clazz == DFSAdmin.class) {
expectDfsAdminPrint(args);
}
pipeOut.close();
ByteStreams.copy(pipeIn, outBytes);
pipeIn.close();
assertTrue(new String(outBytes.toByteArray()).contains(pattern));
} catch (Exception ex) {
fail("checkOutput error " + ex);
} finally {
System.setOut(oldOut);
System.setErr(oldErr);
}
}
use of java.io.PipedInputStream in project textdb by TextDB.
the class TextQLParserTest method string2InputStream.
/**
* Create an InputStream that contains an given String.
* @param s the string to be available in the resulting InputStream
* @return an InputStream containing the string s
*/
private InputStream string2InputStream(String s) {
try {
//create a piped input stream to write to and a piped output stream to return as result
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
//print the string to the stream
PrintStream ppos = new PrintStream(pos);
ppos.print(s);
ppos.close();
//return the generated InputStream
return pis;
} catch (IOException e) {
//return null if an IOException is thrown
return null;
}
}
use of java.io.PipedInputStream in project tesb-studio-se by Talend.
the class RuntimeConsoleUtil method loadConsole.
public static void loadConsole() {
clearConsole();
RuntimeClient client = new RuntimeClient();
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream();
try {
pos.connect(pis);
} catch (IOException e) {
ExceptionHandler.process(e);
}
client.setInputStream(pis);
Thread consoleThread = new Thread("Runtime Console Input") {
@Override
public void run() {
InputStream is = findConsole().getInputStream();
int count = 0;
byte[] bs = new byte[1024];
try {
while ((count = is.read(bs)) > 0) {
// remore duplicate \r\n for Windows
if (count > 1 && bs[count - 1] == 10 && bs[count - 2] == 13) {
count--;
}
pos.write(Arrays.copyOf(bs, count));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
pos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
consoleThread.start();
Thread connectThread = new Thread("Runtime Console Connector") {
@Override
public void run() {
IPreferenceStore store = ESBRunContainerPlugin.getDefault().getPreferenceStore();
String etcLocation = store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_LOCATION);
String host = store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_HOST);
System.setProperty("karaf.etc", etcLocation + "/etc");
String[] karafArgs = new String[] { "-h", host };
try {
client.connect(karafArgs);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
};
connectThread.start();
}
Aggregations