Example usage for java.io BufferedInputStream markSupported

List of usage examples for java.io BufferedInputStream markSupported

Introduction

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

Prototype

public boolean markSupported() 

Source Link

Document

Tests if this input stream supports the mark and reset methods.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    boolean bool = false;

    InputStream inStream = new FileInputStream("c:/test.txt");

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(inStream);

    // returns true if mark() and read() supports
    bool = bis.markSupported();
    System.out.println("Support for mark() and reset() : " + bool);

}

From source file:Main.java

private static Reader getUTF8Reader(InputStream f) throws IOException {
    BufferedInputStream bis = new BufferedInputStream(f);
    assert bis.markSupported();
    bis.mark(3);/*from  w ww.ja v  a  2  s.  c  om*/
    boolean reset = true;
    byte[] t = new byte[3];
    bis.read(t);
    if (t[0] == ((byte) 0xef) && t[1] == ((byte) 0xbb) && t[2] == ((byte) 0xbf)) {
        reset = false;
    }
    if (reset) {
        bis.reset();
    }
    return new InputStreamReader(bis, "UTF-8");
}

From source file:edu.harvard.iq.dataverse.ingest.metadataextraction.impl.plugins.fits.FITSFileMetadataExtractorSpi.java

@Override
public boolean canDecodeInput(BufferedInputStream stream) throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }/*from   w  ww .  j  a v a 2  s. c  om*/

    byte[] b = new byte[FITS_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, FITS_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }
    //printHexDump(b, "hex dump of the byte-array");
    dbgLog.info("hex dump of the 1st " + FITS_HEADER_SIZE + " bytes:"
            + (new String(Hex.encodeHex(b))).toUpperCase());

    if (stream.markSupported()) {
        stream.reset();
    }

    boolean DEBUG = false;

    String hdr4fits = new String(b);

    if (hdr4fits.equals(FITS_FILE_SIGNATURE)) {
        dbgLog.fine("this is a fits file");
        return true;
    } else {
        dbgLog.fine("this is NOT a fits file");
        return false;
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReaderSpi.java

@Override
public boolean canDecodeInput(Object source) throws IOException {
    out.println("this method is actually called: object");
    if (!(source instanceof BufferedInputStream)) {
        return false;
    } else if (source instanceof File) {
        out.println("source is a File object");
    } else {/*  www.  j  a  v a2s.c o m*/
        out.println("not File object");
    }
    if (source == null) {
        throw new IllegalArgumentException("source == null!");
    }
    BufferedInputStream stream = (BufferedInputStream) source;

    dbgLog.fine("applying the sav test\n");

    byte[] b = new byte[SAV_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, SAV_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }
    //printHexDump(b, "hex dump of the byte-array");
    dbgLog.info("hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)));
    if (stream.markSupported()) {
        stream.reset();
    }

    boolean DEBUG = false;

    String hdr4sav = new String(b);
    dbgLog.fine("from string[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)).toUpperCase());

    if (hdr4sav.equals(SAV_FILE_SIGNATURE)) {
        dbgLog.fine("this file is spss-sav type");
        return true;
    } else {
        dbgLog.fine("this file is NOT spss-sav type");
        return false;
    }
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.sav.SAVFileReaderSpi.java

@Override
public boolean canDecodeInput(Object source) throws IOException {
    dbgLog.fine("this method is actually called: object");
    if (!(source instanceof BufferedInputStream)) {
        return false;
    } else if (source instanceof File) {
        dbgLog.fine("source is a File object");
    } else {//w w  w . j a  va  2 s.  c  o  m
        dbgLog.fine("not File object");
    }
    if (source == null) {
        throw new IllegalArgumentException("source == null!");
    }
    BufferedInputStream stream = (BufferedInputStream) source;

    dbgLog.fine("applying the sav test\n");

    byte[] b = new byte[SAV_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, SAV_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }
    //printHexDump(b, "hex dump of the byte-array");
    dbgLog.fine("hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)));
    if (stream.markSupported()) {
        stream.reset();
    }

    boolean DEBUG = false;

    String hdr4sav = new String(b);
    dbgLog.fine("from string[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)).toUpperCase());

    if (hdr4sav.equals(SAV_FILE_SIGNATURE)) {
        dbgLog.fine("this file is spss-sav type");
        return true;
    } else {
        dbgLog.fine("this file is NOT spss-sav type");
        return false;
    }
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReaderSpi.java

@Override
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof BufferedInputStream)) {
        return false;
    }/*from   ww  w .j  a  v  a2 s .co  m*/
    if (source == null) {
        throw new IllegalArgumentException("stream == null!");
    }
    BufferedInputStream stream = (BufferedInputStream) source;
    dbgLog.fine("applying the dta test\n");

    byte[] b = new byte[DTA_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, DTA_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }

    if (stream.markSupported()) {
        stream.reset();
    }

    dbgLog.info("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(b)) + "<-");

    if (b[2] != 1) {
        dbgLog.fine("3rd byte is not 1: given file is not stata-dta type");
        return false;
    } else if ((b[1] != 1) && (b[1] != 2)) {
        dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type");
        return false;
    } else if (!DTAFileReaderSpi.stataReleaseNumber.containsKey(b[0])) {
        dbgLog.fine("1st byte (" + b[0] + ") is not within the ingestable range [rel. 3-10]:"
                + "this file is NOT stata-dta type");
        return false;
    } else {
        dbgLog.fine("this file is stata-dta type: " + DTAFileReaderSpi.stataReleaseNumber.get(b[0])
                + "(No in byte=" + b[0] + ")");
        return true;
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.dta.DTAFileReaderSpi.java

@Override
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof BufferedInputStream)) {
        return false;
    }/* ww w .  j a v  a2 s.c o  m*/
    if (source == null) {
        throw new IllegalArgumentException("stream == null!");
    }
    BufferedInputStream stream = (BufferedInputStream) source;
    dbgLog.fine("applying the dta test\n");

    byte[] b = new byte[DTA_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, DTA_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }
    //printHexDump(b, "hex dump of the byte-array");

    if (stream.markSupported()) {
        stream.reset();
    }

    dbgLog.info("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(b)) + "<-");

    if (b[2] != 1) {
        dbgLog.fine("3rd byte is not 1: given file is not stata-dta type");
        return false;
    } else if ((b[1] != 1) && (b[1] != 2)) {
        dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type");
        return false;
    } else if (!DTAFileReaderSpi.stataReleaseNumber.containsKey(b[0])) {
        dbgLog.fine("1st byte (" + b[0] + ") is not within the ingestable range [rel. 3-10]:"
                + "this file is NOT stata-dta type");
        return false;
    } else {
        dbgLog.fine("this file is stata-dta type: " + DTAFileReaderSpi.stataReleaseNumber.get(b[0])
                + "(No in byte=" + b[0] + ")");
        return true;
    }
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReaderSpi.java

@Override
public boolean canDecodeInput(BufferedInputStream stream) throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }/*www .j  a  v  a  2 s  .co m*/

    dbgLog.fine("applying the dta test\n");

    byte[] b = new byte[DTA_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, DTA_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }

    if (stream.markSupported()) {
        stream.reset();
    }

    dbgLog.info("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(b)) + "<-");

    if (b[2] != 1) {
        dbgLog.fine("3rd byte is not 1: given file is not stata-dta type");
        return false;
    } else if ((b[1] != 1) && (b[1] != 2)) {
        dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type");
        return false;
    } else if (!DTAFileReaderSpi.stataReleaseNumber.containsKey(b[0])) {
        dbgLog.fine("1st byte (" + b[0] + ") is not within the ingestable range [rel. 3-10]:"
                + "this file is NOT stata-dta type");
        return false;
    } else {
        dbgLog.fine("this file is stata-dta type: " + DTAFileReaderSpi.stataReleaseNumber.get(b[0])
                + "(No in HEX=" + b[0] + ")");
        return true;
    }

}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReaderSpi.java

@Override
public boolean canDecodeInput(BufferedInputStream stream) throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }/*from  w w  w  .j a v a  2 s .  c o m*/

    dbgLog.fine("\napplying the sav test: inputstream case\n");

    byte[] b = new byte[SAV_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, SAV_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }
    //printHexDump(b, "hex dump of the byte-array");
    dbgLog.info(
            "hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + (new String(Hex.encodeHex(b))).toUpperCase());

    if (stream.markSupported()) {
        stream.reset();
    }

    boolean DEBUG = false;

    String hdr4sav = new String(b);
    dbgLog.fine("from string[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)).toUpperCase());

    if (hdr4sav.equals(SAV_FILE_SIGNATURE)) {
        dbgLog.fine("this file is spss-sav type");
        return true;
    } else {
        dbgLog.fine("this file is NOT spss-sav type");
        return false;
    }
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.sav.SAVFileReaderSpi.java

@Override
public boolean canDecodeInput(BufferedInputStream stream) throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }/*w  w  w .  j  av a2  s. c  o  m*/

    dbgLog.fine("\napplying the sav test: inputstream case\n");

    byte[] b = new byte[SAV_HEADER_SIZE];

    if (stream.markSupported()) {
        stream.mark(0);
    }
    int nbytes = stream.read(b, 0, SAV_HEADER_SIZE);

    if (nbytes == 0) {
        throw new IOException();
    }
    //printHexDump(b, "hex dump of the byte-array");
    dbgLog.fine(
            "hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + (new String(Hex.encodeHex(b))).toUpperCase());

    if (stream.markSupported()) {
        stream.reset();
    }

    boolean DEBUG = false;

    String hdr4sav = new String(b);
    dbgLog.fine("from string[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)).toUpperCase());

    if (hdr4sav.equals(SAV_FILE_SIGNATURE)) {
        dbgLog.fine("this file is spss-sav type");
        return true;
    } else {
        dbgLog.fine("this file is NOT spss-sav type");
        return false;
    }
}