/** * Deserializes an XCAS from a stream. By default this is not lenient, meaning that if the XCAS * references Types that are not in the Type System, an Exception will be thrown. Use * {@link XCASDeserializer#deserialize(InputStream,CAS,boolean)} to turn on lenient mode and * ignore any unknown types. * * @param aStream * input stream from which to read the XCAS XML document * @param aCAS * CAS into which to deserialize. This CAS must be set up with a type system that is * compatible with that in the XCAS * * @throws SAXException * if an XML Parsing error occurs * @throws IOException * if an I/O failure occurs */ public static void deserialize(InputStream aStream, CAS aCAS) throws SAXException, IOException { XCASDeserializer.deserialize(aStream, aCAS, false); }
@Override public void readFields(DataInput in) throws IOException { int dataLength = in.readInt(); byte[] data = new byte[dataLength]; in.readFully(data); String serializedCAS = new String(data, "UTF-8"); try { XCASDeserializer.deserialize(new ByteArrayInputStream(serializedCAS.getBytes("UTF-8")), cas); } catch (SAXException e) { e.printStackTrace(); } }
/** * @param aCas * the target CAS * @param aFile * the file to read from * @throws IOException * if there is a problem reading the file * @deprecated Use {@link CasIOUtils#load(java.net.URL, CAS)} instead. */ @Deprecated public static void readXCas(CAS aCas, File aFile) throws IOException { InputStream is = null; try { is = new FileInputStream(aFile); XCASDeserializer.deserialize(is, aCas); } catch (SAXException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; // NOPMD // If we were using Java 1.6 and add the wrapped exception to the IOException // constructor, we would not get a warning here } finally { closeQuietly(is); } }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { URI uri = ViewUriUtil.getURI(jCas); InputStream inputStream = null; try { inputStream = uri.toURL().openStream(); switch (this.xmlScheme) { case XMI: XmiCasDeserializer.deserialize(inputStream, jCas.getCas()); break; case XCAS: XCASDeserializer.deserialize(inputStream, jCas.getCas()); break; } inputStream.close(); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { URI uri = ViewUriUtil.getURI(jCas); InputStream inputStream = null; try { inputStream = uri.toURL().openStream(); switch (this.xmlScheme) { case XMI: XmiCasDeserializer.deserialize(inputStream, jCas.getCas()); break; case XCAS: XCASDeserializer.deserialize(inputStream, jCas.getCas()); break; } inputStream.close(); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
public void getNext(JCas jCas) throws IOException, CollectionException { if (!hasNext()) { throw new RuntimeException("getNext(jCas) was called but hasNext() returns false"); } FileInputStream inputStream = new FileInputStream(currentFile); try { if (xmlScheme.equals(XMI)) XmiCasDeserializer.deserialize(inputStream, jCas.getCas()); else XCASDeserializer.deserialize(inputStream, jCas.getCas()); } catch (SAXException e) { throw new CollectionException(e); } finally { inputStream.close(); } completed++; currentFile = null; }
public void getNext(JCas jCas) throws IOException, CollectionException { if (!hasNext()) { throw new RuntimeException("getNext(jCas) was called but hasNext() returns false"); } FileInputStream inputStream = new FileInputStream(currentFile); try { if (xmlScheme.equals(XMI)) XmiCasDeserializer.deserialize(inputStream, jCas.getCas()); else XCASDeserializer.deserialize(inputStream, jCas.getCas()); } catch (SAXException e) { throw new CollectionException(e); } finally { inputStream.close(); } completed++; currentFile = null; }
XCASDeserializer.deserialize(xCasStream, cas); System.out.println("XCAS deserialized");
XCASDeserializer.deserialize(xCasStream, cas); System.out.println("XCAS deserialized");
@Override public void map(Text key, Text value, OutputCollector<Text, CASWritable> output, Reporter reporter) throws IOException { try { CAS cas = CasCreationUtils.createCas(createTypeSystemDescription(), null, null); XCASDeserializer.deserialize(new StringInputStream(value.toString()), cas); // XCASDeserializer.deserialize(IOUtils.toInputStream(value.toString(), "utf8"), cas); CASWritable casWritable = new BinCasWithTypeSystemWritable(); casWritable.setCAS(cas); output.collect(key, casWritable); reporter.incrCounter("hpz", "processed cas", 1); if (cas.getDocumentText() == null) reporter.incrCounter("hpz", "document text null", 1); else reporter.incrCounter("hpz", "doc size", cas.getDocumentText().length()); } catch (Exception e) { reporter.incrCounter("hpz", "exception " + e.getMessage(), 1); e.printStackTrace(System.err); } }
XCASDeserializer.deserialize(fis, aCAS, lenient);