Exemplo n.º 1
0
  public void testBOMMarkers() throws Exception {
    final String fileWithBom = "stopwithbom.txt";
    SolrResourceLoader loader = new SolrResourceLoader("solr/collection1");

    // preliminary sanity check
    InputStream bomStream = loader.openResource(fileWithBom);
    try {
      final byte[] bomExpected = new byte[] {-17, -69, -65};
      final byte[] firstBytes = new byte[3];

      assertEquals(
          "Should have been able to read 3 bytes from bomStream", 3, bomStream.read(firstBytes));

      assertTrue(
          "This test only works if "
              + fileWithBom
              + " contains a BOM -- it appears someone removed it.",
          Arrays.equals(bomExpected, firstBytes));
    } finally {
      try {
        bomStream.close();
      } catch (Exception e) {
        /* IGNORE */
      }
    }

    // now make sure getLines skips the BOM...
    List<String> lines = loader.getLines(fileWithBom);
    assertEquals(1, lines.size());
    assertEquals("BOMsAreEvil", lines.get(0));
  }
Exemplo n.º 2
0
 public void testWrongEncoding() throws Exception {
   String wrongEncoding = "stopwordsWrongEncoding.txt";
   SolrResourceLoader loader = new SolrResourceLoader("solr/collection1");
   // ensure we get our exception
   try {
     List<String> lines = loader.getLines(wrongEncoding);
     fail();
   } catch (SolrException expected) {
     assertTrue(expected.getCause() instanceof CharacterCodingException);
   }
 }