Search in sources :

Example 66 with SequenceInputStream

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);
        }
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 67 with SequenceInputStream

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);
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ImmutableList(com.google.common.collect.ImmutableList) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 68 with SequenceInputStream

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());
}
Also used : SequenceInputStream(java.io.SequenceInputStream) BufferedInputStream(java.io.BufferedInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) Vector(java.util.Vector) URL(java.net.URL)

Example 69 with SequenceInputStream

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
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 70 with SequenceInputStream

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);
}
Also used : SequenceInputStream(java.io.SequenceInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream)

Aggregations

SequenceInputStream (java.io.SequenceInputStream)123 InputStream (java.io.InputStream)78 ByteArrayInputStream (java.io.ByteArrayInputStream)67 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)32 FileInputStream (java.io.FileInputStream)24 BufferedInputStream (java.io.BufferedInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 Vector (java.util.Vector)10 Test (org.junit.Test)10 FileOutputStream (java.io.FileOutputStream)9 List (java.util.List)9 lombok.val (lombok.val)9 File (java.io.File)8 OutputStream (java.io.OutputStream)8 HashMap (java.util.HashMap)8 InputStreamReader (java.io.InputStreamReader)7 ByteBuffer (java.nio.ByteBuffer)6 Support_ASimpleInputStream (tests.support.Support_ASimpleInputStream)6 Reader (java.io.Reader)5