Package javax.xml.transform.stream

Examples of javax.xml.transform.stream.StreamSource


    this.cacheStyleSheet(this.resourceClass,this.path);
  }

  private void cacheStyleSheet(Class<?> resourceClass, String path) throws TransformerConfigurationException{
    InputStream inputStream = resourceClass.getResourceAsStream(path);
    Source xsltSource = new StreamSource(inputStream);
    TransformerFactory transFact = TransformerFactory.newInstance();
    Templates templates = transFact.newTemplates(xsltSource);

    try {inputStream.close();} catch (IOException e) {}
View Full Code Here


            Class<?> c = XMLPerfTest.class;
            String u = c.getResource("/java/lang/String.class").toString();
            final InputStream is = new BufferedInputStream(new URL(u.substring(4,
                    u.indexOf('!'))).openStream());
            final OutputStream os = new IgnoringOutputStream();
            final StreamSource xslt = name == null
                    ? null
                    : new StreamSource(new FileInputStream(name));

            Processor p = new DotObserver(Processor.BYTECODE,
                    outRep,
                    is,
                    os,
View Full Code Here

          .getMediaType(), true);
      Unmarshaller unmarshaller = jaxb.createUnmarshaller();
      unmarshaller
          .setAttachmentUnmarshaller(new XopAttachmentUnmarshaller(
              xopPackage));
      return unmarshaller.unmarshal(new StreamSource(rootPart.getBody(
          InputStream.class, null)));
    } catch (JAXBException e) {
      Response response = Response.serverError().build();
      throw new WebApplicationException(e, response);
    }
View Full Code Here

            SchemaFactory schemaFactory = SchemaFactory.newInstance(config.schemaType());
            try
            {
               InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(
                       config.schema());
               schema = schemaFactory.newSchema(new StreamSource(in));
            }
            catch (SAXException e)
            {
               throw new JAXBException("Error wil trying to load schema for " + config.schema(), e);
            }
View Full Code Here

            }
         }
         JAXBContext jaxb = findJAXBContext(type, annotations, mediaType, true);
         Unmarshaller unmarshaller = jaxb.createUnmarshaller();
         unmarshaller = decorateUnmarshaller(type, annotations, mediaType, unmarshaller);
         return (T) unmarshaller.unmarshal(new StreamSource(entityStream));
      }
      catch (JAXBException e)
      {
         throw new JAXBUnmarshalException(e);
      }
View Full Code Here

    }
   
    saxonDoc = null;
    if (mode.equals("saxon")) {
      if (!cmd.equals("deser")) {
        saxonDoc = context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
      }
    }

    if (mode.startsWith("fi")) {
      doc = new Builder().build(new ByteArrayInputStream(fileData));
View Full Code Here

          .build(new ByteArrayInputStream(fileData));
//        doc2 = staxBuilder.build(staxreader);         
      } else if (mode.startsWith("xom")) {
        doc2 = builder.build(new ByteArrayInputStream(fileData));               
      } else if (mode.equals("saxon")) { // just for deser comparison
        context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
      } else if (mode.equals("dom")) {
        domDoc = null;
        domDoc = domBuilder.parse(new ByteArrayInputStream(fileData));
//          System.err.println(domDoc.getClass().getName());
      } else if (mode.startsWith("fi") && mode.indexOf("stax") >= 0) {
View Full Code Here

              domDoc = domBuilder.parse(file);
            }
           
            NodeInfo saxonDoc = null;
            if (mode.equals("saxon")) {
              saxonDoc = context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
            }
   
            if (mode.startsWith("fi")) {
              if (mode.indexOf("stax") >= 0) {
//                data = serializeWithStax(doc, staxOutputFactory);
                data = serializeWithFastInfosetStax(doc, (XMLStreamWriter)fiSerializer, fiMethod, new ByteArrayOutputStream());
              } else {
                data = serializeWithFastInfoset(doc, (ContentHandler)fiSerializer, fiMethod, new ByteArrayOutputStream());
              }
            }
   
            // run the benchmark
            long start = System.currentTimeMillis();
            for (int i = 0; i < iterations; i++) {
              try {
                // serialize
                if (cmd.equals("ser") || cmd.equals("serdeser") || cmd.equals("test")) {
                  ByteArrayOutputStream out = createOutputStream(cmd.equals("ser"));
                  if (mode.startsWith("bnux")) {
                    if (mode.indexOf("stream") < 0) {
                      codec.serialize(doc, compressionLevel, out);
                      data = out.toByteArray();
                    } else {
                      data = serializeWithStreamingBnux(doc, compressionLevel, out);
                    }
                  } else if (mode.startsWith("xom")) {
                    if (mode.indexOf("stax") >= 0) {
                      data = serializeWithStax(doc, staxOutputFactory, out);
                    } else if (mode.indexOf("stream") < 0) {
                      data = serializeWithXOM(doc, out);
                    } else {
                      data = serializeWithStreamingXOM(doc, out);
                    }
                  } else if (mode.equals("saxon")) {
                    saxonSerializer.transform(saxonDoc, new StreamResult(out));
                    data = out.toByteArray();
                  } else if (mode.equals("dom")) {
                    domSerializer.transform(new DOMSource(domDoc), new StreamResult(out));
                    data = out.toByteArray();
                  } else if (mode.startsWith("fi")) {
                    if (mode.indexOf("stax") >= 0) {
//                      data = serializeWithStax(doc, staxOutputFactory);
                      data = serializeWithFastInfosetStax(doc, (XMLStreamWriter)fiSerializer, fiMethod, out);
                    } else {
                      data = serializeWithFastInfoset(doc, (ContentHandler)fiSerializer, fiMethod, out);
                    }
                  } else {
                    throw new IllegalArgumentException("illegal mode");
                  }
                  checksum += data.length;
                }
                encodedSize = data.length;
                doneEncoded += encodedSize;
               
                // deserialize
                Document doc2 = null;
                if (cmd.equals("deser") || cmd.equals("serdeser") || cmd.equals("test")) {
                  if (mode.startsWith("bnux")) {
                    doc2 = codec.deserialize(new ByteArrayInputStream(data), bnuxFactory);
                  } else if (mode.startsWith("xom") && mode.indexOf("stax") >= 0) {
                    doc2 = staxBuilder.build(new ByteArrayInputStream(fileData));         
                  } else if (mode.startsWith("xom")) {
                    if (mode.indexOf("stream") < 0) {
                      doc2 = builder.build(new ByteArrayInputStream(fileData), baseURI);
                    } else {
                      doc2 = builder.build(new ByteArrayInputStream(data), baseURI);
                    }
                  } else if (mode.equals("saxon")) { // just for deser comparison
                    context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
                  } else if (mode.equals("dom")) {
                    domDoc = domBuilder.parse(new ByteArrayInputStream(fileData));
  //                  System.err.println(domDoc.getClass().getName());
                  } else if (mode.startsWith("fi") && mode.indexOf("stax") >=0 ) {
                    fistaxMethod.invoke(fistaxReader, new Object[] {new ByteArrayInputStream(data)});
View Full Code Here

    if(uriResolver != null){
      transFact.setURIResolver(uriResolver);
    }

    this.templates = transFact.newTemplates(new StreamSource(uri.toString()));
  }
View Full Code Here

      ctx.createMarshaller().marshal(element, writer);
      String s = writer.toString();
      System.out.println(s);

      ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
      StreamSource source = new StreamSource(is);
      JAXBContext ctx2 = JAXBContext.newInstance(JaxbMap.class);
      element = ctx2.createUnmarshaller().unmarshal(source, JaxbMap.class);

      Element entry = (Element) element.getValue().getValue().get(0);
View Full Code Here

TOP

Related Classes of javax.xml.transform.stream.StreamSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.