@Override
    public Charset detect(InputStream input, Metadata metadata) throws IOException {
        input.mark(MAX_BYTES);
        byte[] bytes = new byte[MAX_BYTES];
        try {
            int numRead = IOUtils.read(input, bytes);
            if (numRead < MIN_BYTES) {
                return null;
            } else if (numRead < MAX_BYTES) {
                //s
                byte[] tmpBytes = new byte[numRead];
                System.arraycopy(bytes, 0, tmpBytes, 0, numRead);
                bytes = tmpBytes;
            }
        } finally {
            input.reset();
        }
        for (int i = 0; i < BOMS.length; i++) {
            ByteOrderMark bom = BOMS[i];
            if (startsWith(bom, bytes)) {
                return CHARSETS[i];
            }
        }
        return null;
    }
@Test
    public void testShort() throws Exception {
        EncodingDetector detector = new BOMDetector();
        for (ByteOrderMark bom : new ByteOrderMark[] {
                ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
                ByteOrderMark.UTF_32LE
        }) {
            byte[] bytes = new byte[3];
            System.arraycopy(bom.getBytes(), 0, bytes, 0, 1);
            bytes[1] = (byte)32;
            bytes[2] = (byte)32;
            try (InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get()) {
                assertNull(detector.detect(is, new Metadata()));
            }
        }
    }