Example usage for java.io SequenceInputStream SequenceInputStream

List of usage examples for java.io SequenceInputStream SequenceInputStream

Introduction

In this page you can find the example usage for java.io SequenceInputStream SequenceInputStream.

Prototype

public SequenceInputStream(InputStream s1, InputStream s2) 

Source Link

Document

Initializes a newly created SequenceInputStream by remembering the two arguments, which will be read in order, first s1 and then s2, to provide the bytes to be read from this SequenceInputStream.

Usage

From source file:Main.java

public static void main(String args[]) throws IOException {
    FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
    FileInputStream f2 = new FileInputStream("FileIOApp.java");
    SequenceInputStream inStream = new SequenceInputStream(f1, f2);
    boolean eof = false;
    int byteCount = 0;
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/*from  w  ww.j a  v  a  2 s .c o  m*/
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
    FileInputStream f2 = new FileInputStream("FileIOApp.java");
    inStream = new SequenceInputStream(f1, f2);

    byte[] arrayBytes = new byte[100];
    int c = inStream.read(arrayBytes, 10, 10);

    inStream.close();/*  www. j  a  v  a 2 s  . co  m*/
    f1.close();
    f2.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("file1.java");
    FileInputStream f2 = new FileInputStream("file2.java");
    inStream = new SequenceInputStream(f1, f2);
    boolean eof = false;
    int byteCount = 0;
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/*from   www  .ja  va 2 s  . co  m*/
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
    FileInputStream f2 = new FileInputStream("FileIOApp.java");
    inStream = new SequenceInputStream(f1, f2);
    boolean eof = false;
    int byteCount = 0;
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/* w  w w .j  a  v  a2  s .  c  om*/
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
    FileInputStream f2 = new FileInputStream("FileIOApp.java");
    inStream = new SequenceInputStream(f1, f2);
    boolean eof = false;
    int byteCount = 0;
    System.out.println(inStream.available());
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/*from  www  . j  a v a 2s  .c o m*/
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(inStream.available());
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}

From source file:org.terasoluna.tourreservation.tourreserve.common.constants.MessageKeysGen.java

public static void main(String[] args) throws IOException {
    // message properties file

    InputStream applicationMessagesInputStream = new ClassPathResource(
            "i18n/application-messages_en.properties").getInputStream();
    InputStream validationMessagesInputStream = new ClassPathResource("ValidationMessages_en.properties")
            .getInputStream();//from   ww w  . j  av  a2s  .  c  o m
    SequenceInputStream inputStream = new SequenceInputStream(applicationMessagesInputStream,
            validationMessagesInputStream);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

    Class<?> targetClazz = MessageKeys.class;
    File output = new File(
            "src/test/java/" + targetClazz.getName().replaceAll(Pattern.quote("."), "/") + ".java");
    System.out.println("write " + output.getAbsolutePath());
    PrintWriter pw = new PrintWriter(FileUtils.openOutputStream(output));

    try {
        pw.println("/*");
        pw.println(" * Copyright (C) 2013-2016 NTT DATA Corporation");
        pw.println(" *");
        pw.println(" * Licensed under the Apache License, Version 2.0 (the \"License\");");
        pw.println(" * you may not use this file except in compliance with the License.");
        pw.println(" * You may obtain a copy of the License at");
        pw.println(" *");
        pw.println(" *     http://www.apache.org/licenses/LICENSE-2.0");
        pw.println(" *");
        pw.println(" * Unless required by applicable law or agreed to in writing, software");
        pw.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
        pw.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,");
        pw.println(" * either express or implied. See the License for the specific language");
        pw.println(" * governing permissions and limitations under the License.");
        pw.println(" */");
        pw.println("package " + targetClazz.getPackage().getName() + ";");
        pw.println("/**");
        pw.println(" * Message Id");
        pw.println(" */");
        pw.println("public class " + targetClazz.getSimpleName() + " {");

        String line;
        while ((line = bufferedReader.readLine()) != null) {
            String[] vals = line.split("=", 2);
            if (vals.length > 1) {
                String key = vals[0].trim();
                String value = vals[1].trim();
                pw.println("    /** " + key + "=" + value + " */");
                pw.println("    public static final String " + key.toUpperCase()
                        .replaceAll(Pattern.quote("."), "_").replaceAll(Pattern.quote("-"), "_") + " = \"" + key
                        + "\";");
            }
        }
        pw.println("}");
        pw.flush();
    } finally {
        IOUtils.closeQuietly(applicationMessagesInputStream);
        IOUtils.closeQuietly(validationMessagesInputStream);
        IOUtils.closeQuietly(bufferedReader);
        IOUtils.closeQuietly(pw);
    }
}

From source file:org.fejoa.library.messages.ZipEnvelope.java

static public InputStream zip(InputStream data, boolean isRawData) throws JSONException, IOException {
    JSONObject object = new JSONObject();
    object.put(Envelope.PACK_TYPE_KEY, ZIP_TYPE);
    if (isRawData)
        object.put(Envelope.CONTAINS_DATA_KEY, 1);
    object.put(ZIP_FORMAT_KEY, ZIP_FORMAT);
    String header = object.toString() + "\n";

    return new SequenceInputStream(new ByteArrayInputStream(header.getBytes()), new DeflaterInputStream(data));
}

From source file:org.opentestsystem.delivery.testreg.upload.TextFileAppender.java

@Override
public InputStream insertAtTop(String text, InputStream inputStream) {
    return new SequenceInputStream(getInputStream(text), inputStream);
}

From source file:Main.java

public static InputStream inflate(byte[] deflatedToken, boolean nowrap) throws DataFormatException {
    Inflater inflater = new Inflater(nowrap);
    inflater.setInput(deflatedToken);/*from  www  .j a v  a2  s  .c  om*/

    byte[] input = new byte[deflatedToken.length * 2];
    int inflatedLen = 0;
    int inputLen = 0;
    byte[] inflatedToken = input;
    while (!inflater.finished()) {
        inputLen = inflater.inflate(input);
        if (!inflater.finished()) {

            if (inputLen == 0) {
                if (inflater.needsInput()) {
                    throw new DataFormatException("Inflater can not inflate all the token bytes");
                } else {
                    break;
                }
            }

            inflatedToken = new byte[input.length + inflatedLen];
            System.arraycopy(input, 0, inflatedToken, inflatedLen, inputLen);
            inflatedLen += inputLen;
        }
    }
    InputStream is = new ByteArrayInputStream(input, 0, inputLen);
    if (inflatedToken != input) {
        is = new SequenceInputStream(new ByteArrayInputStream(inflatedToken, 0, inflatedLen), is);
    }
    return is;
}

From source file:com.openshift.internal.restclient.capability.resources.OpenShiftBinaryPodLogRetrieval.java

@Override
public InputStream getLogs(boolean follow) {
    this.follow = follow;
    start();// w  w  w  .j  a  v  a  2s  .  c  om
    SequenceInputStream is = new SequenceInputStream(getProcess().getInputStream(),
            getProcess().getErrorStream());
    return is;
}