Java 类org.apache.commons.io.ByteOrderMark 实例源码

项目:Moenagade    文件:BOMInputStream.java   
/**
 * Return the BOM (Byte Order Mark).
 *
 * @return The BOM or null if none
 * @throws IOException if an error reading the first bytes of the stream occurs
 */
public ByteOrderMark getBOM() throws IOException {
    if (firstBytes == null) {
        int max = 0;
        for (ByteOrderMark bom : boms) {
            max = Math.max(max, bom.length());
        }
        firstBytes = new int[max];
        for (int i = 0; i < firstBytes.length; i++) {
            firstBytes[i] = in.read();
            fbLength++;
            if (firstBytes[i] < 0) {
                break;
            }

            byteOrderMark = find();
            if (byteOrderMark != null) {
                if (!include) {
                    fbLength = 0;
                }
                break;
            }
        }
    }
    return byteOrderMark;
}
项目:dremio-oss    文件:TextRecordWriter.java   
@Override
public void startPartition(WritePartition partition) throws Exception {

  if(this.partition != null){
    close();
  }

  this.partition = partition;
  // open a new file for writing data with new schema
  try {
    this.path = fs.canonicalizePath(partition.qualified(location, prefix + "_" + index + "." + extension));
    DataOutputStream fos = fs.create(path);
    stream = new PrintStream(fos);
    stream.write(ByteOrderMark.UTF_8.getBytes(), 0, ByteOrderMark.UTF_8.length());
    logger.debug("Created file: {}", path);
  } catch (IOException e) {
    throw UserException.dataWriteError(e)
      .message("Failure while attempting to write file %s.", path)
      .build(logger);
  }
  index++;

  stream.print(Joiner.on(fieldDelimiter).join(columnNames));
  stream.print(lineDelimiter);

}
项目:dremio-oss    文件:TextInput.java   
private final boolean checkBom(ByteOrderMark bom) {
  int bomLength = bom.length();
  if (bufferPtr + bomLength >= length) {
    // Not enough bytes from the current position to the end of the buffer
    return false;
  }
  if (BoundsChecking.BOUNDS_CHECKING_ENABLED) {
    buffer.checkBytes(bufferPtr - 1, bufferPtr + bomLength);
  }

  byte[] bomBytes = bom.getBytes();
  for (int i = 0; i < bomLength; i++) {
    byte nextChar = PlatformDependent.getByte(bStartMinus1 + bufferPtr + i);
    if (nextChar != bomBytes[i]) {
      // No BOM. Position is unchanged
      return false;
    }
  }
  return true;
}
项目:dremio-oss    文件:TestNewTextReader.java   
@Test
public void testBomUtf8() throws Exception {
  // Simple .csv file with a UTF-8 BOM. Should read successfully
  File testFolder = tempDir.newFolder("testUtf8Folder");
  File testFile = new File(testFolder, "utf8.csv");
  PrintStream p = new PrintStream(testFile);
  p.write(ByteOrderMark.UTF_8.getBytes(), 0, ByteOrderMark.UTF_8.length());
  p.print("A,B\n");
  p.print("5,7\n");
  p.close();

  testBuilder()
    .sqlQuery(String.format("select * from table(dfs.`%s` (type => 'text', " +
      "fieldDelimiter => ',', lineDelimiter => '\n', extractHeader => true))",
      testFile.getAbsolutePath()))
    .unOrdered()
    .baselineColumns("A","B")
    .baselineValues("5", "7")
    .go();
}
项目:dremio-oss    文件:TestNewTextReader.java   
@Test
public void testErrorBomUtf16() throws Exception {
  // UTF-16 BOM should cause a dataReadError user exception
  File testFolder = tempDir.newFolder("testUtf16Folder");
  File testFile = new File(testFolder, "utf16.csv");
  PrintStream p = new PrintStream(testFile);
  p.write(ByteOrderMark.UTF_16LE.getBytes(), 0, ByteOrderMark.UTF_16LE.length());
  p.print("A,B\n");
  p.print("5,7\n");
  p.close();

  thrownException.expect(new UserExceptionMatcher(UserBitShared.DremioPBError.ErrorType.DATA_READ,
    "DATA_READ ERROR: UTF-16 files not supported"));
  // NB: using test() instead of testBuilder() because it unwraps the thrown RpcException and re-throws the
  // underlying UserException (which is then matched with the UserExceptionMatcher)
  test(String.format("select * from table(dfs.`%s` (type => 'text', " +
      "fieldDelimiter => ',', lineDelimiter => '\n', extractHeader => true))",
    testFile.getAbsolutePath()));
}
项目:sosiefier    文件:BOMInputStreamTest.java   
@Test(timeout = 1000)
public void testReadWithBOM_add139() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWithBOM_add139");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, true));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),382,in,381,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),384,in,383,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),386,in,385,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),387,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),389,in,388,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),391,in,390,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),393,in,392,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),394,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),396,in,395,in.getBOM());
    try {
        in.hasBOM(ByteOrderMark.UTF_16BE);
        in.hasBOM(ByteOrderMark.UTF_16BE);
    } catch (IllegalArgumentException e) {
    }
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:BOMInputStreamTest.java   
public void testReadWithBOM() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWithBOM");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, false));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),382,in,381,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),384,in,383,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),386,in,385,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),387,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),389,in,388,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),391,in,390,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),393,in,392,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),394,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),396,in,395,in.getBOM());
    try {
        in.hasBOM(ByteOrderMark.UTF_16BE);
    } catch (IllegalArgumentException e) {
    }
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:BOMInputStreamTest.java   
public void testReadWithBOMInclude() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWithBOMInclude");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, false) , true);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),360,in,359,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),362,in,361,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),364,in,363,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),366,in,365,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),368,in,367,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),370,in,369,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),371,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),373,in,372,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),375,in,374,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),377,in,376,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),378,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),380,in,379,in.getBOM());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:BOMInputStreamTest.java   
public void testReadWithBOMInclude_literalMutation596() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWithBOMInclude_literalMutation596");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, true) , false);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),360,in,359,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),362,in,361,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),364,in,363,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),366,in,365,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),368,in,367,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),370,in,369,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),371,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),373,in,372,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),375,in,374,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),377,in,376,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),378,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),380,in,379,in.getBOM());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:BOMInputStreamTest.java   
public void testGetBOMFirstThenReadInclude() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testGetBOMFirstThenReadInclude");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, false) , true);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),275,in,274,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),277,in,276,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),278,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),280,in,279,in.getBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),282,in,281,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),284,in,283,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),286,in,285,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),288,in,287,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),290,in,289,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),292,in,291,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),293,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),295,in,294,in.read());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:BOMInputStreamTest.java   
public void testGetBOMFirstThenReadInclude_literalMutation488() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testGetBOMFirstThenReadInclude_literalMutation488");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, true) , false);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),275,in,274,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),277,in,276,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),278,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),280,in,279,in.getBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),282,in,281,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),284,in,283,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),286,in,285,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),288,in,287,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),290,in,289,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),292,in,291,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),293,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),295,in,294,in.read());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:BOMInputStreamTest.java   
public void testReadWithMultipleBOM() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWithMultipleBOM");
    byte[] data = new byte[]{ 'A' , 'B' , 'C' };
    BOMInputStream in = new BOMInputStream(createDataStream(data, false) , ByteOrderMark.UTF_16BE , ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),398,in,397,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),400,in,399,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),402,in,401,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),403,-1);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),405,in,404,in.read());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),407,in,406,in.hasBOM());
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),409,in,408,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_8));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),411,in,410,in.hasBOM(org.apache.commons.io.ByteOrderMark.UTF_16BE));
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),412,org.apache.commons.io.ByteOrderMark.UTF_8);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),414,in,413,in.getBOM());
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:org.fastnate    文件:AbstractCsvReader.java   
/**
 * Opens a CSV file.
 *
 * If the given file ends with "gz", then the file is decompressed before using a {@link GZIPInputStream}.
 *
 * @param importFile
 *            the csv file
 * @return a list reader
 * @throws IOException
 *             on io exception
 */
@SuppressWarnings("resource")
protected CsvListReader openCsvListReader(final File importFile) throws IOException {
    // Open file
    InputStream fileStream = new FileInputStream(importFile);

    // Check for compressed file
    if (importFile.getName().toLowerCase().endsWith(".gz")) {
        fileStream = new GZIPInputStream(fileStream);
    }

    // Guess the encoding
    final BOMInputStream inputStream = new BOMInputStream(fileStream, false, ByteOrderMark.UTF_8,
            ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
    final String charset;
    if (inputStream.hasBOM()) {
        charset = inputStream.getBOMCharsetName();
        log.info("BOM detected. Using {} as encoding", charset);
    } else {
        charset = getDefaultEncoding().toString();
        log.info("No BOM detected. Assuming {} as encoding", charset);
    }
    final Reader reader = new InputStreamReader(inputStream, charset);
    return new CsvListReader(reader, new CsvPreference.Builder(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE)
            .skipComments(new CommentMatches("(//|/\\*|#|;).*")).build());
}
项目:KJBE    文件:BOMInputStream.java   
/**
 * Return the BOM (Byte Order Mark).
 *
 * @return The BOM or null if none
 * @throws IOException if an error reading the first bytes of the stream occurs
 */
public ByteOrderMark getBOM() throws IOException {
    if (firstBytes == null) {
        int max = 0;
        for (ByteOrderMark bom : boms) {
            max = Math.max(max, bom.length());
        }
        firstBytes = new int[max];
        for (int i = 0; i < firstBytes.length; i++) {
            firstBytes[i] = in.read();
            fbLength++;
            if (firstBytes[i] < 0) {
                break;
            }

            byteOrderMark = find();
            if (byteOrderMark != null) {
                if (!include) {
                    fbLength = 0;
                }
                break;
            }
        }
    }
    return byteOrderMark;
}
项目:file-type-plugin    文件:FileType.java   
private String showByteOfMark(InputStream source) throws IOException {
  ByteOrderMark detectedBOM = new BOMInputStream(source).getBOM();
  if (detectedBOM == null) {
    return "";
  }
  String bom = detectedBOM.toString();
  FileType.logger.log(Level.INFO, "BOM: {0}", bom);
  return " w/ " + bom;
}
项目:Moenagade    文件:BOMInputStream.java   
/**
 * Constructs a new BOM InputStream that detects the
 * specified BOMs and optionally includes them.
 * @param delegate the InputStream to delegate to
 * @param include true to include the specified BOMs or
 * false to exclude them
 * @param boms The BOMs to detect and optionally exclude
 */
public BOMInputStream(InputStream delegate, boolean include, ByteOrderMark... boms) {
    super(delegate);
    if (boms == null || boms.length == 0) {
        throw new IllegalArgumentException("No BOMs specified");
    }
    this.include = include;
    this.boms = Arrays.asList(boms);
}
项目:Moenagade    文件:BOMInputStream.java   
/**
 * Find a BOM with the specified bytes.
 *
 * @return The matched BOM or null if none matched
 */
private ByteOrderMark find() {
    for (ByteOrderMark bom : boms) {
        if (matches(bom)) {
            return bom;
        }
    }
    return null;
}
项目:Moenagade    文件:BOMInputStream.java   
/**
 * Check if the bytes match a BOM.
 *
 * @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;
    }
    for (int i = 0; i < bom.length(); i++) {
        if (bom.get(i) != firstBytes[i]) {
            return false;
        }
    }
    return true;
}
项目:instalint    文件:FileMetadata.java   
private static InputStream streamFile(File file) {
  try {
    return new BOMInputStream(new FileInputStream(file),
      ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
  } catch (FileNotFoundException e) {
    throw new IllegalStateException("File not found: " + file.getAbsolutePath(), e);
  }
}
项目:lams    文件:BOMInputStream.java   
public int compare(ByteOrderMark bom1, ByteOrderMark bom2) {
    int len1 = bom1.length();
    int len2 = bom2.length();
    if (len1 > len2) {
        return -1;
    }
    if (len2 > len1) {
        return 1;
    }
    return 0;
}
项目:lams    文件:BOMInputStream.java   
/**
 * Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
 * 
 * @param delegate
 *            the InputStream to delegate to
 * @param include
 *            true to include the specified BOMs or false to exclude them
 * @param boms
 *            The BOMs to detect and optionally exclude
 */
public BOMInputStream(InputStream delegate, boolean include, ByteOrderMark... boms) {
    super(delegate);
    if (boms == null || boms.length == 0) {
        throw new IllegalArgumentException("No BOMs specified");
    }
    this.include = include;
    // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
    Arrays.sort(boms, ByteOrderMarkLengthComparator);
    this.boms = Arrays.asList(boms);

}
项目:lams    文件:BOMInputStream.java   
/**
 * Return the BOM (Byte Order Mark).
 * 
 * @return The BOM or null if none
 * @throws IOException
 *             if an error reading the first bytes of the stream occurs
 */
public ByteOrderMark getBOM() throws IOException {
    if (firstBytes == null) {
        fbLength = 0;
        // BOMs are sorted from longest to shortest
        final int maxBomSize = boms.get(0).length();
        firstBytes = new int[maxBomSize];
        // Read first maxBomSize bytes
        for (int i = 0; i < firstBytes.length; i++) {
            firstBytes[i] = in.read();
            fbLength++;
            if (firstBytes[i] < 0) {
                break;
            }
        }
        // match BOM in firstBytes
        byteOrderMark = find();
        if (byteOrderMark != null) {
            if (!include) {
                if (byteOrderMark.length() < firstBytes.length) {
                    fbIndex = byteOrderMark.length();
                } else {
                    fbLength = 0;
                }
            }
        }
    }
    return byteOrderMark;
}
项目:lams    文件:BOMInputStream.java   
/**
 * Find a BOM with the specified bytes.
 * 
 * @return The matched BOM or null if none matched
 */
private ByteOrderMark find() {
    for (ByteOrderMark bom : boms) {
        if (matches(bom)) {
            return bom;
        }
    }
    return null;
}
项目:lams    文件:BOMInputStream.java   
/**
 * Check if the bytes match a BOM.
 * 
 * @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;
}
项目:dremio-oss    文件:TextInput.java   
private final void skipOptionalBOM() throws IOException {
  if (checkBom(ByteOrderMark.UTF_8)) {
    bufferPtr += ByteOrderMark.UTF_8.length();
  } else if (checkBom(ByteOrderMark.UTF_16LE) || checkBom(ByteOrderMark.UTF_16BE)) {
    throw UserException.dataReadError()
      .message("UTF-16 files not supported")
      .build(logger);
  }
}
项目:WidgetStore    文件:BOMInputStream.java   
public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) {
    final int len1 = bom1.length();
    final int len2 = bom2.length();
    if (len1 > len2) {
        return EOF;
    }
    if (len2 > len1) {
        return 1;
    }
    return 0;
}
项目:WidgetStore    文件:BOMInputStream.java   
/**
 * Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
 * 
 * @param delegate
 *            the InputStream to delegate to
 * @param include
 *            true to include the specified BOMs or false to exclude them
 * @param boms
 *            The BOMs to detect and optionally exclude
 */
public BOMInputStream(final InputStream delegate, final boolean include, final ByteOrderMark... boms) {
    super(delegate);
    if (boms == null || boms.length == 0) {
        throw new IllegalArgumentException("No BOMs specified");
    }
    this.include = include;
    // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
    Arrays.sort(boms, ByteOrderMarkLengthComparator);
    this.boms = Arrays.asList(boms);

}
项目:WidgetStore    文件:BOMInputStream.java   
/**
 * Return the BOM (Byte Order Mark).
 * 
 * @return The BOM or null if none
 * @throws IOException
 *             if an error reading the first bytes of the stream occurs
 */
public ByteOrderMark getBOM() throws IOException {
    if (firstBytes == null) {
        fbLength = 0;
        // BOMs are sorted from longest to shortest
        final int maxBomSize = boms.get(0).length();
        firstBytes = new int[maxBomSize];
        // Read first maxBomSize bytes
        for (int i = 0; i < firstBytes.length; i++) {
            firstBytes[i] = in.read();
            fbLength++;
            if (firstBytes[i] < 0) {
                break;
            }
        }
        // match BOM in firstBytes
        byteOrderMark = find();
        if (byteOrderMark != null) {
            if (!include) {
                if (byteOrderMark.length() < firstBytes.length) {
                    fbIndex = byteOrderMark.length();
                } else {
                    fbLength = 0;
                }
            }
        }
    }
    return byteOrderMark;
}
项目:WidgetStore    文件:BOMInputStream.java   
/**
 * Find a BOM with the specified bytes.
 * 
 * @return The matched BOM or null if none matched
 */
private ByteOrderMark find() {
    for (final ByteOrderMark bom : boms) {
        if (matches(bom)) {
            return bom;
        }
    }
    return null;
}
项目:WidgetStore    文件:BOMInputStream.java   
/**
 * Check if the bytes match a BOM.
 * 
 * @param bom
 *            The BOM
 * @return true if the bytes match the bom, otherwise false
 */
private boolean matches(final 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;
}
项目:JAATP    文件:BOMInputStream.java   
public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) {
    final int len1 = bom1.length();
    final int len2 = bom2.length();
    if (len1 > len2) {
        return EOF;
    }
    if (len2 > len1) {
        return 1;
    }
    return 0;
}
项目:JAATP    文件:BOMInputStream.java   
/**
 * Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
 * 
 * @param delegate
 *            the InputStream to delegate to
 * @param include
 *            true to include the specified BOMs or false to exclude them
 * @param boms
 *            The BOMs to detect and optionally exclude
 */
public BOMInputStream(final InputStream delegate, final boolean include, final ByteOrderMark... boms) {
    super(delegate);
    if (boms == null || boms.length == 0) {
        throw new IllegalArgumentException("No BOMs specified");
    }
    this.include = include;
    // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
    Arrays.sort(boms, ByteOrderMarkLengthComparator);
    this.boms = Arrays.asList(boms);

}
项目:JAATP    文件:BOMInputStream.java   
/**
 * Return the BOM (Byte Order Mark).
 * 
 * @return The BOM or null if none
 * @throws IOException
 *             if an error reading the first bytes of the stream occurs
 */
public ByteOrderMark getBOM() throws IOException {
    if (firstBytes == null) {
        fbLength = 0;
        // BOMs are sorted from longest to shortest
        final int maxBomSize = boms.get(0).length();
        firstBytes = new int[maxBomSize];
        // Read first maxBomSize bytes
        for (int i = 0; i < firstBytes.length; i++) {
            firstBytes[i] = in.read();
            fbLength++;
            if (firstBytes[i] < 0) {
                break;
            }
        }
        // match BOM in firstBytes
        byteOrderMark = find();
        if (byteOrderMark != null) {
            if (!include) {
                if (byteOrderMark.length() < firstBytes.length) {
                    fbIndex = byteOrderMark.length();
                } else {
                    fbLength = 0;
                }
            }
        }
    }
    return byteOrderMark;
}
项目:JAATP    文件:BOMInputStream.java   
/**
 * Find a BOM with the specified bytes.
 * 
 * @return The matched BOM or null if none matched
 */
private ByteOrderMark find() {
    for (final ByteOrderMark bom : boms) {
        if (matches(bom)) {
            return bom;
        }
    }
    return null;
}
项目:JAATP    文件:BOMInputStream.java   
/**
 * Check if the bytes match a BOM.
 * 
 * @param bom
 *            The BOM
 * @return true if the bytes match the bom, otherwise false
 */
private boolean matches(final 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;
}
项目:webz-server    文件: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 {
            actualEncoding = bom.getCharsetName();
            actualNumberOfBytes = downloader.getFileSpecific().getNumberOfBytes() - bom.length();
        }
        reader = new InputStreamReader(bomIn, actualEncoding);
    }
项目:VectorAttackScanner    文件:BOMInputStream.java   
public int compare(ByteOrderMark bom1, ByteOrderMark bom2) {
    int len1 = bom1.length();
    int len2 = bom2.length();
    if (len1 > len2) {
        return -1;
    }
    if (len2 > len1) {
        return 1;
    }
    return 0;
}
项目:VectorAttackScanner    文件:BOMInputStream.java   
/**
 * Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
 * 
 * @param delegate
 *            the InputStream to delegate to
 * @param include
 *            true to include the specified BOMs or false to exclude them
 * @param boms
 *            The BOMs to detect and optionally exclude
 */
public BOMInputStream(InputStream delegate, boolean include, ByteOrderMark... boms) {
    super(delegate);
    if (boms == null || boms.length == 0) {
        throw new IllegalArgumentException("No BOMs specified");
    }
    this.include = include;
    // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
    Arrays.sort(boms, ByteOrderMarkLengthComparator);
    this.boms = Arrays.asList(boms);

}
项目:VectorAttackScanner    文件:BOMInputStream.java   
/**
 * Return the BOM (Byte Order Mark).
 * 
 * @return The BOM or null if none
 * @throws IOException
 *             if an error reading the first bytes of the stream occurs
 */
public ByteOrderMark getBOM() throws IOException {
    if (firstBytes == null) {
        fbLength = 0;
        // BOMs are sorted from longest to shortest
        final int maxBomSize = boms.get(0).length();
        firstBytes = new int[maxBomSize];
        // Read first maxBomSize bytes
        for (int i = 0; i < firstBytes.length; i++) {
            firstBytes[i] = in.read();
            fbLength++;
            if (firstBytes[i] < 0) {
                break;
            }
        }
        // match BOM in firstBytes
        byteOrderMark = find();
        if (byteOrderMark != null) {
            if (!include) {
                if (byteOrderMark.length() < firstBytes.length) {
                    fbIndex = byteOrderMark.length();
                } else {
                    fbLength = 0;
                }
            }
        }
    }
    return byteOrderMark;
}
项目:VectorAttackScanner    文件:BOMInputStream.java   
/**
 * Find a BOM with the specified bytes.
 * 
 * @return The matched BOM or null if none matched
 */
private ByteOrderMark find() {
    for (ByteOrderMark bom : boms) {
        if (matches(bom)) {
            return bom;
        }
    }
    return null;
}