Examples of StreamSource


Examples of com.addthis.meshy.service.stream.StreamSource

                        fileSource.waitComplete();
                        for (FileReference file : fileSource.getFileList()) {
                            System.out.println(file.getHostUUID() + " " + file.name + " \t " + file.size + " \t " + new Date(file.lastModified));
                        }
                    } else if (cmd.equals("cat") && args.length > 5) {
                        StreamSource source = null;
                        String uuid = args[4];
                        String file = args[5];
                        if (args.length > 6) {
                            int buffer = 0;
                            Map<String, String> params = null;
                            params = new HashMap<>();
                            for (int i = 6; i < args.length; i++) {
                                String kv[] = Strings.splitArray(args[i], "=");
                                if (kv[0].equals("--buffer")) {
                                    buffer = Integer.parseInt(kv[1]);
                                } else {
                                    params.put(kv[0], kv[1]);
                                }
                            }
                            source = new StreamSource(more, uuid, file, params, buffer);
                        } else {
                            source = new StreamSource(more, uuid, file, 0);
                        }
                        try (InputStream in = source.getInputStream()) {
                            byte[] buffer = new byte[4096];
                            int read = 0;
                            while ((read = in.read(buffer)) >= 0) {
                                if (read == 0) {
                                    continue;
                                }
                                if (read < 0) {
                                    break;
                                }
                                System.out.write(buffer, 0, read);
                            }
                        }
                        source.waitComplete();
                    } else if (cmd.equals("peer")) {
                        HostSource hostSource = new HostSource(more);
                        for (int i = 4; i < args.length; i++) {
                            hostSource.addPeer(args[i]);
                        }
                        hostSource.sendRequest();
                        hostSource.waitComplete();
                        for (HostNode node : hostSource.getHostList()) {
                            System.out.println(node.uuid + " \t " + node.address);
                        }
                    } else if (cmd.equals("madcat") && args.length > 5) {
                    /* usage: madcat <readers> <bufferSize> <filematch> */
                        int threads = Integer.parseInt(args[4]);
                        final int bufferSize = Integer.parseInt(args[5]);
                        final String fileMatch[] = {args[6]};
                        final DecimalFormat number = new DecimalFormat("#,###");
                        final AtomicLong totalBytes = new AtomicLong(0);
                        final AtomicLong readBytes = new AtomicLong(0);
                        final AtomicLong lastEmit = new AtomicLong(JitterClock.globalTime());
                        final FileSource fs = new FileSource(more, fileMatch, new DupFilter());
                        fs.waitComplete();
                        final Iterator<FileReference> fsIter = fs.getFileList().iterator();
                        final HashMap<FileReference, Long> perfData = new HashMap<>();
                        final AtomicInteger open = new AtomicInteger(0);

                        class SourceReader extends Thread {

                            private FileReference current;
                            private StreamSource source;
                            private InputStream in;
                            private long start;

                            SourceReader(FileReference ref) throws IOException {
                                setup(ref);
                            }

                            private void setup(FileReference ref) throws IOException {
                                if (in != null) {
                                    perfData.put(current, System.currentTimeMillis() - start);
                                    source.waitComplete();
                                    in.close();
                                }
                                if (ref != null) {
                                    start = System.currentTimeMillis();
                                    source = new StreamSource(more, ref.getHostUUID(), ref.name, bufferSize);
                                    in = source.getInputStream();
                                    current = ref;
                                }
                            }

                            public void run() {
View Full Code Here

Examples of com.caucho.vfs.StreamSource

      if (valueHash.equals(oldValueHash))
        return valueHash;

      int length = os.getLength();

      StreamSource source = new StreamSource(os);
      if (! getDataBacking().saveData(valueHash, source, length)) {
        throw new IllegalStateException(L.l("Can't save the data '{0}'",
                                       valueHash));
      }
View Full Code Here

Examples of com.dotcms.repackage.javax.xml.transform.stream.StreamSource

        if(!XMLPath.startsWith("http")){
          Identifier xmlId = APILocator.getIdentifierAPI().find(host, XMLPath);
          if(xmlId!=null && InodeUtils.isSet(xmlId.getId()) && xmlId.getAssetType().equals("contentlet")){
            Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(xmlId.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), userAPI.getSystemUser(),false);
            if(cont!=null && InodeUtils.isSet(cont.getInode())){
              xmlSource = new StreamSource(new InputStreamReader(new FileInputStream(cont.getBinary(FileAssetAPI.BINARY_FIELD)), "UTF8"));
            }
          }else{
            File xmlFile = fileAPI.getFileByURI(XMLPath, host, true,userAPI.getSystemUser(),false);
            xmlSource = new StreamSource(new InputStreamReader(new FileInputStream(fileAPI.getAssetIOFile(xmlFile)), "UTF8"));
          }

        }else{
          xmlSource = new StreamSource(XMLPath);
        }

        Source xsltSource = new StreamSource(new InputStreamReader(new FileInputStream(binFile), "UTF8"));

        // create an instance of TransformerFactory
        TransformerFactory transFact = TransformerFactory.newInstance();
        StreamResult result = new StreamResult(new ByteArrayOutputStream());
        Transformer trans = transFact.newTransformer(xsltSource);
View Full Code Here

Examples of com.vaadin.server.StreamResource.StreamSource

    }

    protected void download(String target) {
        String filename = "filename";
        StreamResource streamResource = new StreamResource(new StreamSource() {

            @Override
            public InputStream getStream() {
                try {
                    return new FileInputStream("FIXME C:/temp/file.xls");
View Full Code Here

Examples of com.vaadin.terminal.StreamResource.StreamSource

   
    Label processTitle = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
    processTitle.addStyleName(ExplorerLayout.STYLE_H3);
    processImageContainer.addComponent(processTitle);
   
    StreamSource streamSource = null;
    byte[] editorSourceExtra = repositoryService.getModelEditorSourceExtra(modelData.getId());
    if (editorSourceExtra != null) {
      InputStream svgStream = new ByteArrayInputStream(editorSourceExtra);
      TranscoderInput input = new TranscoderInput(svgStream);
     
      PNGTranscoder transcoder = new PNGTranscoder();
      try {
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);
       
        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        outStream.close();
       
        streamSource = new StreamSource() {
          private static final long serialVersionUID = 1L;
 
          public InputStream getStream() {
            InputStream inStream = null;
            if (result != null) {
View Full Code Here

Examples of javax.xml.transform.stream.StreamSource

  private static void transformConfig(File config, String styleSheet, Result target)
      throws TransformerFactoryConfigurationError,
      TransformerConfigurationException, TransformerException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer(new StreamSource(MigrationUtil.class.getResourceAsStream(styleSheet)));
    t.setParameter("version", ApplicationInfo.getInstance().getReleaseNumber()); //$NON-NLS-1$
    t.transform(new StreamSource(config), target);
  }
View Full Code Here

Examples of javax.xml.transform.stream.StreamSource

        } else if (o instanceof OMElement) {
            OMElement omElement = (OMElement) o;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                omElement.serialize(baos);
                return new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
            } catch (XMLStreamException e) {
                handleException("Error converting to a StreamSource", e);
            }

        } else if (o instanceof OMText) {
            DataHandler dataHandler = (DataHandler) ((OMText) o).getDataHandler();
            if (dataHandler != null) {
                try {
                    return new StreamSource(dataHandler.getInputStream());
                } catch (IOException e) {
                    handleException("Error in reading content as a stream ");
                }
            }
        } else {
View Full Code Here

Examples of javax.xml.transform.stream.StreamSource

        public static String transform(String stylesheet,
                                       String srcXMLString,
                                       HashMap<String, String> params) throws Exception {
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult( writer );
            Source src = new StreamSource( new StringReader( srcXMLString ) );
            transform( stylesheet,
                       src,
                       result,
                       params );
            return writer.toString();
View Full Code Here

Examples of javax.xml.transform.stream.StreamSource

            InputStream xslStream = null;

            try {
                InputStream in = XSLTransformation.class.getResourceAsStream( stylesheet );
                xslStream = new BufferedInputStream( in );
                StreamSource src = new StreamSource( xslStream );
                src.setSystemId( stylesheet );
                transformer = TransformerFactory.newInstance().newTransformer( src );
            } finally {
                if ( xslStream != null ) xslStream.close();
            }
View Full Code Here

Examples of javax.xml.transform.stream.StreamSource

    public static void closeSource(final Source source) {
      if (!(source instanceof StreamSource)) {
        return;
      }
     
      StreamSource stream = (StreamSource)source;
      try {
        if (stream.getInputStream() != null) {
          stream.getInputStream().close();
        }
      } catch (IOException e) {
      }
      try {
        if (stream.getReader() != null) {
          stream.getReader().close();
        }
      } catch (IOException e) {
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.