Example usage for java.io SequenceInputStream close

List of usage examples for java.io SequenceInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

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();
    f1.close();//from   w ww .  j  ava2s.  c om
    f2.close();
}

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 av a  2  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("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 ww w . j  a v  a2s.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;//from w  w  w .  j  a va  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);
    boolean eof = false;
    int byteCount = 0;
    System.out.println(inStream.available());
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/*w  w w. java  2  s . c  om*/
        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:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static String calcMD5HashForDir(File dirToHash, boolean includeSubFolders, boolean includeHiddenFiles) {

    assert (dirToHash.isDirectory());
    Vector<FileInputStream> fileStreams = new Vector<FileInputStream>();

    logger.debug("Found files for hashing:");
    collectInputStreams(dirToHash, fileStreams, includeSubFolders, includeHiddenFiles);

    SequenceInputStream seqStream = new SequenceInputStream(fileStreams.elements());

    try {//from  w  w  w.j ava  2s .c om
        String md5Hash = DigestUtils.md5Hex(seqStream);
        seqStream.close();
        return md5Hash;
    } catch (IOException e) {
        throw new RuntimeException("Error reading files to hash in " + dirToHash.getAbsolutePath(), e);
    }

}

From source file:org.cloudifysource.dsl.internal.DSLReader.java

@SuppressWarnings("deprecation")
private Object evaluateGroovyScript(final GroovyShell gs) throws DSLValidationException {
    // Evaluate class using a FileReader, as the *-service files create a
    // class with an illegal name
    Object result = null;/*from   ww  w . jav  a  2 s  . co  m*/

    if (this.dslContents == null) {

        //FileReader reader = null;
        SequenceInputStream sis = null;
        try {

            final FileInputStream fis = new FileInputStream(dslFile);
            final ByteArrayInputStream bis = new ByteArrayInputStream(GROOVY_SERVICE_PREFIX.getBytes());
            sis = new SequenceInputStream(bis, fis);
            //reader = new FileReader(dslFile);
            // using a deprecated method here as we do not have a multireader in the dependencies
            // and not really worth another jar just for this.
            result = gs.evaluate(sis, "dslEntity");
        } catch (final IOException e) {
            throw new IllegalStateException("The file " + dslFile + " could not be read", e);
        } catch (final MissingMethodException e) {
            throw new IllegalArgumentException("Could not resolve DSL entry with name: " + e.getMethod(), e);
        } catch (final MissingPropertyException e) {
            throw new IllegalArgumentException("Could not resolve DSL entry with name: " + e.getProperty(), e);
        } catch (final DSLValidationRuntimeException e) {
            throw e.getDSLValidationException();
        } finally {
            if (sis != null) {
                try {
                    sis.close();
                } catch (final IOException e) {
                    // ignore
                }
            }
        }
    } else {
        try {
            result = gs.evaluate(this.dslContents, "dslEntity");
        } catch (final CompilationFailedException e) {
            throw new IllegalArgumentException("The file " + dslFile + " could not be compiled", e);
        }

    }
    return result;
}

From source file:rapture.blob.mongodb.GridFSBlobHandler.java

protected GridFSInputFile updateExisting(CallingContext context, String docPath, InputStream newContent,
        GridFS gridFS, GridFSDBFile existing) throws IOException {
    GridFSInputFile file;/*from  ww w .ja v  a 2  s.  c o  m*/
    String lockKey = createLockKey(gridFS, docPath);
    LockHandle lockHandle = grabLock(context, lockKey);
    try {
        File tempFile = File.createTempFile("rapture", "blob");
        existing.writeTo(tempFile);
        FileInputStream tempIn = FileUtils.openInputStream(tempFile);
        SequenceInputStream sequence = new SequenceInputStream(tempIn, newContent);
        try {
            gridFS.remove(docPath);
            file = createNewFile(docPath, sequence);
            if (!tempFile.delete()) {
                log.warn(String.format("Unable to delete temp file created while appending docPath %s, at %s",
                        docPath, tempFile.getAbsolutePath()));
            }
        } finally {
            try {
                sequence.close();
            } catch (IOException e) {
                log.error(
                        String.format("Error closing sequence input stream: %s", ExceptionToString.format(e)));
            }
            try {
                tempIn.close();
            } catch (IOException e) {
                log.error(
                        String.format("Error closing sequence input stream: %s", ExceptionToString.format(e)));
            }
        }
    } finally {
        releaseLock(context, lockKey, lockHandle);
    }
    return file;
}

From source file:uk.ac.soton.simulation.jsit.core.ModelVersioningAssistant.java

String calcMD5HashForFileList(List<File> pathsToHash, boolean includeHiddenFiles, File[] fileExclusions,
        String[] filenameExclusions, boolean printFileNames) {

    Vector<FileInputStream> fileStreams = new Vector<FileInputStream>();
    ArrayList<File> workingFileExcludeList = null;

    if (printFileNames) {
        logger.info("Found files for hashing:");
    }/*w w  w . ja v  a  2 s. c o  m*/

    try {
        if (fileExclusions != null) {
            workingFileExcludeList = new ArrayList<File>(fileExclusions.length);
            for (File f : fileExclusions) {
                assert f.exists();
                workingFileExcludeList.add(f.getAbsoluteFile());
            }
        }
        for (File currPath : pathsToHash) {
            assert currPath.exists();
            if (currPath.isDirectory()) {
                collectInputStreams(currPath, fileStreams, workingFileExcludeList, filenameExclusions,
                        includeHiddenFiles, printFileNames);
            } else if (currPath.isFile()) {
                if (printFileNames) {
                    logger.info("\t" + currPath.getAbsolutePath());
                }
                if (!fileIsExcluded(includeHiddenFiles, workingFileExcludeList, filenameExclusions, currPath)) {
                    fileStreams.add(new FileInputStream(currPath));
                }
            } else {
                assert false; // Should never happen!
            }
        }

        SequenceInputStream seqStream = new SequenceInputStream(fileStreams.elements());
        String md5Hash = DigestUtils.md5Hex(seqStream);
        seqStream.close();
        return md5Hash;
    } catch (IOException e) {
        throw new VersionControlException("Error reading files to hash", e);
    }

}