Inheritance: java.io.Writer
Beispiel #1
0
		public TextExtractionResult Extract(Func<Metadata, InputStream> streamFactory)
		{
			try
			{
				var parser = new AutoDetectParser();
				var metadata = new Metadata();
				var outputWriter = new StringWriter();
				var parseContext = new ParseContext();

                //use the base class type for the key or parts of Tika won't find a usable parser
				parseContext.set(typeof(org.apache.tika.parser.Parser), parser);
				
				using (var inputStream = streamFactory(metadata))
				{
					try
					{
						parser.parse(inputStream, getTransformerHandler(outputWriter), metadata, parseContext);
					}
					finally
					{
						inputStream.close();
					}
				}

				return assembleExtractionResult(outputWriter.ToString(), metadata);
			}
			catch (Exception ex)
			{
				throw new TextExtractionException("Extraction failed.", ex);
			}
		}
Beispiel #2
0
        static void Main(string[] args)
        {
            System.IO.File.Delete(@"temp.txt");
            System.IO.File.Delete(@"output.txt");
            System.IO.File.Delete(@"C:\\Main\\Walmart\\walmart.txt");

            string[] files = System.IO.Directory.GetFiles("C:\\Main\\Walmart", "*.pdf", System.IO.SearchOption.TopDirectoryOnly);

            if (files.Length == 0)
                return;

            foreach (String file in files)
            {
                StringWriter text = new StringWriter(1024);
                System.Console.Write("{0}\n", file);
                using (Document doc = PDF.open(file))
                {
                    System.Console.Clear();
                    System.Console.WriteLine("Please Wait.. Generating Files..");
                    doc.pipe(new OutputTarget(text));
                }
                System.IO.File.AppendAllText(@"temp.txt", text.toString());
                text.close();
            }
            parseTextNew();
        }
Beispiel #3
0
        public static string ToString(Table table, TableContainType tableContainType)
        {
            java.io.StringWriter stringWriter = new java.io.StringWriter();
            try
            {
                technology.tabula.writers.Writer writer = null;
                switch (tableContainType)
                {
                case TableContainType.CSV:
                    writer = new CSVWriter();
                    break;

                case TableContainType.Json:
                    writer = new JSONWriter();
                    break;

                case TableContainType.TSV:
                    writer = new TSVWriter();
                    break;

                default:
                    writer = new JSONWriter();
                    break;
                }

                writer.write(stringWriter, table);
            }
            catch
            {
                return(string.Empty);
            }
            return(stringWriter.toString());
        }
Beispiel #4
0
        protected TransformerHandler CreateTransformerHandler(StringWriter output)
        {
            var factory = TransformerFactory.newInstance() as SAXTransformerFactory;
            var handler = factory.newTransformerHandler();
            handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "text");
            handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");

            handler.setResult(new StreamResult(output));
            return handler;
        }
Beispiel #5
0
 public static JObject ProcessText(string text)
 {
     var annotation = new Annotation(text);
     using (java.io.StringWriter writer = new java.io.StringWriter())
     {
         pipeline.annotate(annotation);
         pipeline.jsonPrint(annotation, writer);
         return JObject.Parse(writer.toString());
     }
 }
Beispiel #6
0
        public static JObject ProcessText(string text)
        {
            var annotation = new Annotation(text);

            using (java.io.StringWriter writer = new java.io.StringWriter())
            {
                pipeline.annotate(annotation);
                pipeline.jsonPrint(annotation, writer);
                return(JObject.Parse(writer.toString()));
            }
        }
Beispiel #7
0
        /// <summary>
        /// Convert mol to V3000 Molfile
        /// </summary>
        /// <param name="mol"></param>
        /// <returns></returns>

        public static string AtomContainerToMolFileV3000(IAtomContainer mol)
        {
            java.io.StringWriter sw = new java.io.StringWriter();

            MDLV3000Writer writer = new MDLV3000Writer(sw);

            writer.write(mol);
            writer.close();
            sw.close();

            string molFile = sw.toString();

            return(molFile);
        }
Beispiel #8
0
 public string ExtractText(byte[] data)
 {
     var parser = new AutoDetectParser();
     var handler = new BodyContentHandler();
     var context = new ParseContext();
     context.set(parser.getClass(), parser);
     var metadata = new Metadata();
     using (var output = new StringWriter()) {
         var transformerHandler = CreateTransformerHandler(output);
         using (var inputStream = TikaInputStream.get(data, metadata)) {
             parser.parse(inputStream, transformerHandler, metadata, context);
             inputStream.close();
         }
         return output.toString();
     }
 }
Beispiel #9
0
        public override string format(LogRecord logrecord)
        {
            var stringbuilder = new StringBuilder();
            stringbuilder.append(dateFormat.format(Long.valueOf(logrecord.getMillis())));
            Level level = logrecord.getLevel();
            if (level == Level.FINEST)
            {
                stringbuilder.append(" [FINEST] ");
            }
            else if (level == Level.FINER)
            {
                stringbuilder.append(" [FINER] ");
            }
            else if (level == Level.FINE)
            {
                stringbuilder.append(" [FINE] ");
            }
            else if (level == Level.INFO)
            {
                stringbuilder.append(" [INFO] ");
            }
            else if (level == Level.WARNING)
            {
                stringbuilder.append(" [WARNING] ");
            }
            else if (level == Level.SEVERE)
            {
                stringbuilder.append(" [SEVERE] ");
            }
            else if (level == Level.SEVERE)
            {
                stringbuilder.append(
                    (new StringBuilder()).append(" [").append(level.getLocalizedName()).append("] ").toString());
            }
            stringbuilder.append(logrecord.getMessage());
            stringbuilder.append('\n');
            var throwable = logrecord.getThrown() as Throwable;
            if (throwable != null)
            {
                var stringwriter = new StringWriter();
                throwable.printStackTrace(new PrintWriter(stringwriter));
                stringbuilder.append(stringwriter.toString());
            }

            Debug.WriteLine(stringbuilder.toString());
            return stringbuilder.toString();
        }
        public virtual RewriterResults rewrite(Gadget gadget, MutableContent content)
        {
            java.io.StringWriter sw   = new java.io.StringWriter();
            GadgetSpec           spec = gadget.getSpec();
            Uri  _base = spec.getUrl();
            View view  = gadget.getCurrentView();

            if (view != null && view.getHref() != null)
            {
                _base = view.getHref();
            }
            if (rewrite(spec, _base, content, "text/html", sw))
            {
                content.setContent(sw.toString());
            }
            return(null);
        }
Beispiel #11
0
        public void InternalFixBeforeAdobt()
        {
            // why does this fix our attribute value problem??
            // <output id="Content"><div><a href="&#10;  ">sdfsdfsdf</a></div></output>
            // X:\jsc.svn\examples\php\PHPWiki\PHPWiki\ApplicationWebService.cs


            try
            {
                this.InternalEnsureElement();

                var s = new DOMSource(this.InternalValue);
                var w = new StringWriter();

                var r = new StreamResult(w);

                var f = TransformerFactory.newInstance();

                f.newTransformer().transform(s, r);
            }
            catch
            {
                // X:\jsc.svn\examples\javascript\forms\FormsNIC\FormsNIC\ApplicationWebService.cs


                //Caused by: java.lang.NullPointerException
                //       at org.apache.xml.serializer.ToStream.writeAttrString(ToStream.java:2099)
                //       at org.apache.xml.serializer.ToStream.processAttributes(ToStream.java:2079)
                //       at org.apache.xml.serializer.ToStream.closeStartTag(ToStream.java:2623)
                //       at org.apache.xml.serializer.ToStream.characters(ToStream.java:1410)
                //       at org.apache.xalan.transformer.TransformerIdentityImpl.characters(TransformerIdentityImpl.java:1126)
                //       at org.apache.xml.serializer.TreeWalker.dispatachChars(TreeWalker.java:246)
                //       at org.apache.xml.serializer.TreeWalker.startNode(TreeWalker.java:416)
                //       at org.apache.xml.serializer.TreeWalker.traverse(TreeWalker.java:145)
                //       at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:390)
                //       at ScriptCoreLibJava.BCLImplementation.System.Xml.Linq.__XNode.InternalFixBeforeAdobt(__XNode.java:77)
                //       ... 25 more

                throw;
            }

        }
Beispiel #12
0
 public virtual RewriterResults rewrite(Gadget gadget, MutableContent content)
 {
     java.io.StringWriter sw = new java.io.StringWriter();
     GadgetSpec spec = gadget.getSpec();
     Uri _base = spec.getUrl();
     View view = gadget.getCurrentView();
     if (view != null && view.getHref() != null) 
     {
         _base = view.getHref();
     }
     if (rewrite(spec, _base, content, "text/html", sw)) 
     {
         content.setContent(sw.toString());
     }
     return null;
 }
Beispiel #13
0
        public string InternalToString()
        {
            // http://faq.javaranch.com/java/DocumentToString
            var value = default(string);

            //Console.WriteLine("InternalToString " + new { this.InternalValue });
            try
            {


                //I/System.Console(12089): Caused by: java.lang.NullPointerException
                //I/System.Console(12089):        at org.apache.xml.serializer.ToStream.writeAttrString(ToStream.java:2099)
                //I/System.Console(12089):        at org.apache.xml.serializer.ToStream.processAttributes(ToStream.java:2079)
                //I/System.Console(12089):        at org.apache.xml.serializer.ToStream.closeStartTag(ToStream.java:2623)
                //I/System.Console(12089):        at org.apache.xml.serializer.ToStream.startElement(ToStream.java:1927)
                //I/System.Console(12089):        at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1073)
                //I/System.Console(12089):        at org.apache.xml.serializer.TreeWalker.startNode(TreeWalker.java:359)
                //I/System.Console(12089):        at org.apache.xml.serializer.TreeWalker.traverse(TreeWalker.java:145)
                //I/System.Console(12089):        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:390)
                //I/System.Console(12089):        at ScriptCoreLibJava.BCLImplementation.System.Xml.Linq.__XNode.InternalToString(__XNode.java:81)


                this.InternalEnsureElement();

                // http://stackoverflow.com/questions/9150403/how-do-you-debug-an-xml-object-that-causes-a-transform-error-when-writing-to-str
                // http://dotcommers.wordpress.com/2008/10/22/javaxxmltransformtransformerexception-javalangnullpointerexception-how-to-solve/


                var s = new DOMSource(this.InternalValue);
                var w = new StringWriter();
                var r = new StreamResult(w);
                var f = TransformerFactory.newInstance();
                var transformer =  f.newTransformer();

                // http://stackoverflow.com/questions/15592025/transformer-setoutputpropertyoutputkeys-encoding-utf-8-is-not-working
                transformer.setOutputProperty(OutputKeys.METHOD, "xml");

                // meses up fields as cookie headers?
                //transformer.setOutputProperty(OutputKeys.INDENT, "yes");

                transformer.transform(s, r);

                value = w.getBuffer().toString();

                #region __XDocument
                var IsDocument = (this is __XDocument);
                if (!IsDocument)
                {
                    // hack.

                    {
                        var prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

                        if (value.StartsWith(prefix))
                            value = value.Substring(prefix.Length);
                    }

                    {
                        var prefix = "\r\n";

                        if (value.StartsWith(prefix))
                            value = value.Substring(prefix.Length);
                    }
                }
                #endregion

            }
            catch (Exception err)
            {
                //  Message = java.lang.RuntimeException: Namespace for prefix 'xsi' has not been declared., StackTrace = jav
                // The input node can not be null for a DOMSource for newTemplates!


                // Z:\jsc.svn\examples\java\hybrid\JVMCLRWSDLMID\Program.cs

                //throw;

                value = err.Message;
            }

            return value;
        }
 public static string getFilteredTrace(Exception t)
 {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter((Writer) stringWriter);
   Throwable.instancehelper_printStackTrace(t, printWriter);
   return BaseTestRunner.getFilteredTrace(stringWriter.getBuffer().toString());
 }
Beispiel #15
0
 private static string exceptionToString([In] Exception obj0)
 {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter((Writer) stringWriter);
   Throwable.instancehelper_printStackTrace(obj0, printWriter);
   return stringWriter.toString();
 }
Beispiel #16
0
 public virtual string getTrace()
 {
   StringWriter stringWriter = new StringWriter();
   Throwable.instancehelper_printStackTrace(this.getException(), new PrintWriter((Writer) stringWriter));
   return stringWriter.getBuffer().toString();
 }
Beispiel #17
0
		private TransformerHandler getTransformerHandler(StringWriter output)
		{
			var factory = (SAXTransformerFactory) TransformerFactory.newInstance();
			var transformerHandler = factory.newTransformerHandler();
			
			transformerHandler.getTransformer().setOutputProperty(OutputKeys.METHOD, "text");
			transformerHandler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");

			transformerHandler.setResult(new StreamResult(output));
			return transformerHandler;
		}
		public void save(IFile file) {
			try {
				var document = XmlHelper.load(new StringReader(EMPTY_DOC));
				var libs = (Element)document.getElementsByTagName("libraries").item(0);
				foreach (var lib in this.Libraries) {
					var e = document.createElement("library");
					libs.appendChild(e);
					e.setAttribute("name", lib.Path);
					if (!lib.Enabled) {
						e.setAttribute("enabled", "false");
					}
				}
				if (this.PreprocessorSymbols.any()) {
					var sb = new StringBuilder();
					var first = true;
					foreach (String s in this.PreprocessorSymbols) {
						if (first) {
							first = false;
						} else {
							sb.append(';');
						}
						sb.append(s);
					}
					var e = document.createElement("preprocessorSymbols");
					document.getDocumentElement().appendChild(e);
					e.setTextContent(sb.toString());
				}
				var outputElt = document.createElement("outputPath");
				document.getDocumentElement().appendChild(outputElt);
				outputElt.setTextContent(this.OutputPath);
				
	            var writer = new StringWriter();
				XmlHelper.save(document, writer);
	            var bytes = writer.toString().getBytes("UTF-8");
	            var stream = new ByteArrayInputStream(bytes);
	            if (file.exists()) {
	            	file.setContents(stream, IResource.FORCE, null);
	            } else {
	            	file.create(stream, true, null);
	            }
			} catch (Exception e) {
				Environment.logException(e);
			}
		}
    public static string getFilteredTrace(string stack)
    {
      if (BaseTestRunner.showStackRaw())
        return stack;
      StringWriter stringWriter = new StringWriter();
      PrintWriter printWriter = new PrintWriter((Writer) stringWriter);
      BufferedReader bufferedReader = new BufferedReader((Reader) new StringReader(stack));
      try
      {
        string str;
        while ((str = bufferedReader.readLine()) != null)
        {
          if (!BaseTestRunner.filterLine(str))
            printWriter.println(str);
        }
        goto label_9;
      }
      catch (Exception ex)
      {
        int num = 2;
        if (ByteCodeHelper.MapException<Exception>(ex, (ByteCodeHelper.MapFlags) num) == null)
          throw;
      }
      return stack;
label_9:
      return stringWriter.toString();
    }