public WordFastTMReader(String filename, String encoding) throws IOException { super(filename, encoding); //skip the header (first line) if (nextLine != null) { nextLine = in.readLine(); nextPair = tab2StringPair(nextLine); } }
@Test public void testReader() throws Exception { // Create a simple WordFast text memory. File input = File.createTempFile("input", ".txt"); input.deleteOnExit(); // Populate the file with data. try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(input), "UTF-8"))) { writer.println("%20100801~111517\t%UserID,AHLJat,AHLJat\t%TU=00008580\t%EN-US\t%Wordfast TM v.546/00\t%PL-PL\t%\t."); writer.println("20100727~145333\tAHLJat\t2\tEN-US\tObjection:\tPL-PL\tZarzut: "); writer.println("20100727~051350\tAHLJat\t2\tEN-US\tWhy not?&tA;\tPL-PL\tDlaczego nie?&tA; "); } WordFastTMReader reader = new WordFastTMReader(input.getAbsolutePath(), "UTF-8"); int i = 1; for (StringPair srcAndTrg : reader) { assertTrue(srcAndTrg.getSource() != null); assertTrue(srcAndTrg.getTarget() != null); if (i == 1) { assertEquals("Objection:", srcAndTrg.getSource()); } else if (i == 2) { assertEquals("Why not?&tA;", srcAndTrg.getSource()); } i++; } } }
@Override public StringPair next() { try { StringPair result = nextPair; if (nextLine != null) { nextLine = in.readLine(); nextPair = tab2StringPair(nextLine); if (nextLine == null) { in.close(); } } return result; } catch (IOException e) { throw new RuntimeException(e); } }
public WordFastTMReader(String filename, String encoding) throws IOException { super(filename, encoding); //skip the header (first line) if (nextLine != null) { nextLine = in.readLine(); nextPair = tab2StringPair(nextLine); } }
@Override public StringPair next() { try { StringPair result = nextPair; if (nextLine != null) { nextLine = in.readLine(); nextPair = tab2StringPair(nextLine); if (nextLine == null) { in.close(); } } return result; } catch (IOException e) { throw new RuntimeException(e); } }