Example usage for org.apache.commons.io ByteOrderMark length

List of usage examples for org.apache.commons.io ByteOrderMark length

Introduction

In this page you can find the example usage for org.apache.commons.io ByteOrderMark length.

Prototype

public int length() 

Source Link

Document

Return the length of the BOM's bytes.

Usage

From source file:com.examples.with.different.packagename.idnaming.BOMInputStream.java

/**
 * Check if the bytes match a BOM.//from   ww  w .  j  av a2 s.c  om
 * 
 * @param bom
 *            The BOM
 * @return true if the bytes match the bom, otherwise false
 */
private boolean matches(ByteOrderMark bom) {
    // if (bom.length() != fbLength) {
    // return false;
    // }
    // firstBytes may be bigger than the BOM bytes
    for (int i = 0; i < bom.length(); i++) {
        if (bom.get(i) != firstBytes[i]) {
            return false;
        }
    }
    return true;
}

From source file:org.sonar.scanner.scan.filesystem.ByteCharsetDetector.java

private static boolean isBom(ByteOrderMark bom, byte[] buffer) {
    if (buffer.length < bom.length()) {
        return false;
    }//w w  w.j ava2s.  c o m
    for (int i = 0; i < bom.length(); i++) {
        if ((byte) bom.get(i) != buffer[i]) {
            return false;
        }
    }
    return true;
}

From source file:org.sonar.scanner.scan.filesystem.CharsetDetector.java

private boolean detectCharset(byte[] buf) throws IOException {
    ByteCharsetDetector detector = new ByteCharsetDetector(new CharsetValidation(), userEncoding);
    ByteOrderMark bom = detector.detectBOM(buf);
    if (bom != null) {
        detectedCharset = Charset.forName(bom.getCharsetName());
        stream.skip(bom.length());
        return true;
    }//w  w w .ja  v a2s . c om

    detectedCharset = detector.detect(buf);
    return detectedCharset != null;
}

From source file:org.terems.webz.internals.FileDownloaderWithBOM.java

public FileDownloaderWithBOM(WebzInputStreamDownloader downloader, String defaultEncoding)
        throws IOException, WebzException {

    this.bomIn = (BOMInputStream) new BOMInputStream(downloader.getInputStream(), false, ALL_BOMS);
    this.downloader = new FileDownloader(downloader.getFileSpecific(), bomIn);
    ByteOrderMark bom = bomIn.getBOM();

    if (bom == null) {
        actualEncoding = defaultEncoding;
        actualNumberOfBytes = downloader.getFileSpecific().getNumberOfBytes();
    } else {//  ww  w  .  j  a  v  a 2 s . c o  m
        actualEncoding = bom.getCharsetName();
        actualNumberOfBytes = downloader.getFileSpecific().getNumberOfBytes() - bom.length();
    }
    reader = new InputStreamReader(bomIn, actualEncoding);
}