Search in sources :

Example 1 with DocumentImpl

use of gate.corpora.DocumentImpl in project gate-core by GateNLP.

the class TestRepositioningInfo method testRepositioningInfo.

// tearDown
/**
 * This method tests if Repositinioning Information works.
 * It creates a document using an xml file with preserveOriginalContent
 * and collectRepositioningInfo options keeping true and which has all
 * sorts of special entities like &amp, &quot etc. + it contains both
 * kind of unix and dos stype new line characters.  It then saves the
 * document to the temporary location on the disk using
 * "save preserving document format" option and then compares the contents of
 * both the original and the temporary document to see if they are equal.
 * @throws java.lang.Exception
 */
public void testRepositioningInfo() throws Exception {
    // here we need to save the document to the file
    String encoding = ((DocumentImpl) doc).getEncoding();
    File outputFile = File.createTempFile("test-inline1", "xml");
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
    writer.write(doc.toXml(null, true));
    writer.flush();
    writer.close();
    Reader readerForSource = new BomStrippingInputStreamReader(new URL(testFile).openStream(), encoding);
    Reader readerForDesti = new BomStrippingInputStreamReader(new FileInputStream(outputFile), encoding);
    while (true) {
        int input1 = readerForSource.read();
        int input2 = readerForDesti.read();
        if (input1 < 0 || input2 < 0) {
            assertTrue(input1 < 0 && input2 < 0);
            readerForSource.close();
            readerForDesti.close();
            outputFile.delete();
            return;
        } else {
            assertEquals(input1, input2);
        }
    }
}
Also used : BomStrippingInputStreamReader(gate.util.BomStrippingInputStreamReader) FileOutputStream(java.io.FileOutputStream) Reader(java.io.Reader) BomStrippingInputStreamReader(gate.util.BomStrippingInputStreamReader) OutputStreamWriter(java.io.OutputStreamWriter) DocumentImpl(gate.corpora.DocumentImpl) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Aggregations

DocumentImpl (gate.corpora.DocumentImpl)1 BomStrippingInputStreamReader (gate.util.BomStrippingInputStreamReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 URL (java.net.URL)1