use of java.io.SequenceInputStream in project alluxio by Alluxio.
the class ProcessLauncher method start.
/**
* Starts an Alluxio process of the given type.
*
* @param type the alluxio process type to launch
*
* @throws IOException if there is an issue creating the subprocess
* @throws InterruptedException if the thread is interrupted while waiting for the process to
* start
*/
public void start(AlluxioNodeType type) throws IOException, InterruptedException {
String cmd = type.toString().toLowerCase();
Process p = Runtime.getRuntime().exec(String.format("%s %s", mScript, cmd));
SequenceInputStream is = new SequenceInputStream(p.getInputStream(), p.getErrorStream());
BufferedReader output = new BufferedReader(new InputStreamReader(is));
try {
List<String> lines = output.lines().collect(Collectors.toList());
while (true) {
if (p.waitFor(500, TimeUnit.MILLISECONDS)) {
break;
}
}
LOG.debug("process launch output for {}:\n{}", type, lines);
} catch (UncheckedIOException e) {
LogUtils.warnWithException(LOG, "Failed to launch Alluxio process {}", type, e);
} finally {
// Clean after launching the process
try {
is.close();
} catch (IOException e) {
LOG.debug("Failed to properly close stdin writer when starting {}", type, e);
}
try {
output.close();
} catch (IOException e) {
LOG.debug("Failed to properly close stdout/err reader when starting {}", type, e);
}
}
}
use of java.io.SequenceInputStream in project buck by facebook.
the class LogConfig method setupLogging.
/**
* Creates the log output directory and concatenates logging.properties
* files together to configure or re-configure LogManager.
*/
public static synchronized void setupLogging(LogConfigSetup logConfigSetup) throws IOException {
// Bug JDK-6244047: The default FileHandler does not handle the directory not existing,
// so we have to create it before any log statements actually run.
Files.createDirectories(logConfigSetup.getLogDir());
if (logConfigSetup.getRotateLog()) {
try {
deleteOldLogFiles(logConfigSetup);
} catch (IOException e) {
System.err.format("Error deleting old log files (ignored): %s\n", e.getMessage());
}
}
ImmutableList.Builder<InputStream> inputStreamsBuilder = ImmutableList.builder();
if (!LogConfigPaths.MAIN_PATH.isPresent()) {
System.err.format("Error: Couldn't read system property %s (it should be set by buck_common or buck.cmd)\n", LogConfigPaths.BUCK_CONFIG_STRING_TEMPLATE_FILE_PROPERTY);
} else {
if (!addInputStreamForTemplate(LogConfigPaths.MAIN_PATH.get(), logConfigSetup, inputStreamsBuilder)) {
System.err.format("Error: Couldn't open logging properties file %s\n", LogConfigPaths.MAIN_PATH.get());
}
}
// We ignore the return value for these files; they don't need to exist.
addInputStreamForPath(LogConfigPaths.PROJECT_PATH, inputStreamsBuilder);
addInputStreamForPath(LogConfigPaths.LOCAL_PATH, inputStreamsBuilder);
// for log settings.
try (InputStream is = new SequenceInputStream(Iterators.asEnumeration(inputStreamsBuilder.build().iterator()))) {
LogManager.getLogManager().readConfiguration(is);
}
}
use of java.io.SequenceInputStream in project openhab1-addons by openhab.
the class TTSServiceGoogleTTS method getSpeechForText.
/**
* Converts the given sentences into audio and returns it as an {@link InputStream}.
*
* @param sentences
* The text to be converted to audio
* @return {@link InputStream} with audio output
* @throws IOException
* Exception if the connection could not be established properly
*/
private InputStream getSpeechForText(List<String> sentences) throws IOException {
Vector<InputStream> inputStreams = new Vector<InputStream>(sentences.size());
for (String sentence : sentences) {
String encodedSentence = GoogleTTSTextProcessor.urlEncodeSentence(sentence);
URL url = new URL(String.format(translateUrl, ttsLanguage, encodedSentence));
inputStreams.add(getInputStreamFromUrl(url));
}
return new SequenceInputStream(inputStreams.elements());
}
use of java.io.SequenceInputStream in project robovm by robovm.
the class OldSequenceInputStreamTest method test_read$BII_Excpetion.
public void test_read$BII_Excpetion() throws IOException {
byte[] buf = new byte[4];
si.read(buf, 0, 2);
si.read(buf, 2, 1);
simple2.throwExceptionOnNextUse = true;
si.read(buf, 3, 1);
assertEquals("Wrong stuff read!", "Hell", new String(buf));
simple1.throwExceptionOnNextUse = true;
try {
si.read(buf, 3, 1);
fail("IOException not thrown!");
} catch (IOException e) {
// expected
}
buf = new byte[10];
simple1 = new Support_ASimpleInputStream(s1);
simple2 = new Support_ASimpleInputStream(s2);
si = new SequenceInputStream(simple1, simple2);
try {
si.read(buf, -1, 1);
fail("IndexOutOfBoundsException was not thrown");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
si.read(buf, 0, -1);
fail("IndexOutOfBoundsException was not thrown");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
si.read(buf, 1, 10);
fail("IndexOutOfBoundsException was not thrown");
} catch (IndexOutOfBoundsException e) {
// Expected
}
}
use of java.io.SequenceInputStream in project robovm by robovm.
the class OldSequenceInputStreamTest method setUp.
protected void setUp() {
simple1 = new Support_ASimpleInputStream(s1);
simple2 = new Support_ASimpleInputStream(s2);
si = new SequenceInputStream(simple1, simple2);
}
Aggregations