Search in sources :

Example 31 with CSVReader

use of au.com.bytecode.opencsv.CSVReader in project tika by apache.

the class MetadataResourceTest method testSimpleWord.

@Test
public void testSimpleWord() throws Exception {
    Response response = WebClient.create(endPoint + META_PATH).type("application/msword").accept("text/csv").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
    Reader reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
    CSVReader csvReader = new CSVReader(reader);
    Map<String, String> metadata = new HashMap<String, String>();
    String[] nextLine;
    while ((nextLine = csvReader.readNext()) != null) {
        metadata.put(nextLine[0], nextLine[1]);
    }
    csvReader.close();
    assertNotNull(metadata.get("Author"));
    assertEquals("Maxim Valyanskiy", metadata.get("Author"));
    assertEquals("X-TIKA:digest:MD5", "f8be45c34e8919eedba48cc8d207fbf0", metadata.get("X-TIKA:digest:MD5"));
}
Also used : Response(javax.ws.rs.core.Response) InputStreamReader(java.io.InputStreamReader) CSVReader(au.com.bytecode.opencsv.CSVReader) HashMap(java.util.HashMap) CSVReader(au.com.bytecode.opencsv.CSVReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Test(org.junit.Test)

Example 32 with CSVReader

use of au.com.bytecode.opencsv.CSVReader in project tika by apache.

the class MetadataResourceTest method testPasswordProtected.

@Test
public void testPasswordProtected() throws Exception {
    Response response = WebClient.create(endPoint + META_PATH).type("application/vnd.ms-excel").accept("text/csv").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_PASSWORD_PROTECTED));
    // Won't work, no password given
    assertEquals(500, response.getStatus());
    // Try again, this time with the wrong password
    response = WebClient.create(endPoint + META_PATH).type("application/vnd.ms-excel").accept("text/csv").header("Password", "wrong password").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_PASSWORD_PROTECTED));
    assertEquals(500, response.getStatus());
    // Try again, this time with the password
    response = WebClient.create(endPoint + META_PATH).type("application/vnd.ms-excel").accept("text/csv").header("Password", "password").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_PASSWORD_PROTECTED));
    // Will work
    assertEquals(200, response.getStatus());
    // Check results
    Reader reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
    CSVReader csvReader = new CSVReader(reader);
    Map<String, String> metadata = new HashMap<String, String>();
    String[] nextLine;
    while ((nextLine = csvReader.readNext()) != null) {
        metadata.put(nextLine[0], nextLine[1]);
    }
    csvReader.close();
    assertNotNull(metadata.get("Author"));
    assertEquals("pavel", metadata.get("Author"));
}
Also used : Response(javax.ws.rs.core.Response) InputStreamReader(java.io.InputStreamReader) CSVReader(au.com.bytecode.opencsv.CSVReader) HashMap(java.util.HashMap) CSVReader(au.com.bytecode.opencsv.CSVReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Test(org.junit.Test)

Aggregations

CSVReader (au.com.bytecode.opencsv.CSVReader)32 StringReader (java.io.StringReader)12 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 HttpClient (org.apache.commons.httpclient.HttpClient)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 InputStreamReader (java.io.InputStreamReader)4 HashMap (java.util.HashMap)4 JSONObject (org.json.simple.JSONObject)4 JSONParser (org.json.simple.parser.JSONParser)4 Query (au.org.ala.spatial.util.Query)3 FileReader (java.io.FileReader)3 ZipEntry (java.util.zip.ZipEntry)3 ZipInputStream (java.util.zip.ZipInputStream)3 JSONArray (org.json.simple.JSONArray)3 ParseException (org.json.simple.parser.ParseException)3 Event (org.zkoss.zk.ui.event.Event)3 Facet (au.org.ala.legend.Facet)2 LegendObject (au.org.ala.legend.LegendObject)2 SelectedArea (au.org.emii.portal.menu.SelectedArea)2