Package net.yacy.kelondro.io

Examples of net.yacy.kelondro.io.CharBuffer


    public boolean isIdentityTransformer() {
        return bluelist.isEmpty();
    }

    private static char[] genBlueLetters(int length) {
            final CharBuffer bb = new CharBuffer(" <FONT COLOR=#0000FF>".toCharArray());
            length = length / 2;
            if (length > 10) length = 7;
            while (length-- > 0) {
                bb.append((int)'X');
            }
            bb.append("</FONT> ");
            final char[] result = bb.getChars();
            try {
        bb.close();
      } catch (IOException e) {
          Log.logException(e);
      }
            return result;
    }
View Full Code Here


   
    private Document[] parse(final MultiProtocolURI location, final String mimeType,
            final String charset, final File dest)
            throws Parser.Failure, InterruptedException {
       
        CharBuffer writer = null;
        try {         
            String docDescription = null;
            String docKeywordStr  = null;
            String docShortTitle  = null;
            String docLongTitle   = null;
            String docAuthor      = null;
            String docLanguage    = null;
           
            // opening the file as zip file
            final ZipFile zipFile = new ZipFile(dest);
            final Enumeration<? extends ZipEntry> zipEnum = zipFile.entries();
            final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
           
            // looping through all containing files
            while (zipEnum.hasMoreElements()) {
               
                // getting the next zip file entry
                final ZipEntry zipEntry= zipEnum.nextElement();
                final String entryName = zipEntry.getName();
               
                // content.xml contains the document content in xml format
                if (entryName.equals("content.xml")) {
                   
                    // create a writer for output
                    writer = new CharBuffer();
                   
                    // extract data
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    saxParser.parse(zipFileEntryStream, new ODContentHandler(writer));
               
                    // close readers and writers
                    zipFileEntryStream.close();
                    writer.close();
                   
                } else if (entryName.equals("meta.xml")) {
                    //  meta.xml contains metadata about the document
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    final ODMetaHandler metaData = new ODMetaHandler();
                    saxParser.parse(zipFileEntryStream, metaData);
                    docDescription = metaData.getDescription();
                    docKeywordStr  = metaData.getKeyword();
                    docShortTitle  = metaData.getTitle();
                    docLongTitle   = metaData.getSubject();
                    docAuthor      = metaData.getCreator();
                    docLanguage    = metaData.getLanguage();
                }
            }
           
            // make the languages set
            final Set<String> languages = new HashSet<String>(1);
            if (docLanguage != null) languages.add(docLanguage);
           
            // if there is no title availabe we generate one
            if (docLongTitle == null) {
                if (docShortTitle != null) {
                    docLongTitle = docShortTitle;
                }
            }           
        
            // split the keywords
            String[] docKeywords = null;
            if (docKeywordStr != null) docKeywords = docKeywordStr.split(" |,");
           
            // create the parser document
            Document[] docs = null;
            final byte[] contentBytes = UTF8.getBytes(writer.toString());
            docs = new Document[]{new Document(
                    location,
                    mimeType,
                    "UTF-8",
                    this,
                    languages,
                    docKeywords,
                    docLongTitle,
                    docAuthor,
                    "",
                    null,
                    docDescription,
                    0.0f, 0.0f,
                    contentBytes,
                    null,
                    null,
                    null,
                    false)};
            return docs;
        } catch (final Exception e) {           
            if (e instanceof InterruptedException) throw (InterruptedException) e;
            if (e instanceof Parser.Failure) throw (Parser.Failure) e;
           
            // close the writer
            if (writer != null) try { writer.close(); } catch (final Exception ex) {/* ignore this */}
           
            throw new Parser.Failure("Unexpected error while parsing odt file. " + e.getMessage(),location);
        }
    }
View Full Code Here

        }

        if (docTitle == null || docTitle.length() == 0) {
            docTitle = MultiProtocolURI.unescape(location.getFileName());
        }
        CharBuffer writer = null;
        try {
            // create a writer for output
            PDFTextStripper stripper = null;
            writer = new CharBuffer();
            stripper = new PDFTextStripper();
            stripper.writeText(pdfDoc, writer); // may throw a NPE
            pdfDoc.close();
            writer.close();
        } catch (final IOException e) {
            // close the writer
            if (writer != null) try { writer.close(); } catch (final Exception ex) {}
            try {pdfDoc.close();} catch (final IOException ee) {}
            //throw new Parser.Failure(e.getMessage(), location);
        } catch (final NullPointerException e) {
            // this exception appeared after the insertion of the jempbox-1.5.0.jar library
            Log.logException(e);
            // close the writer
            if (writer != null) try { writer.close(); } catch (final Exception ex) {}
            try {pdfDoc.close();} catch (final IOException ee) {}
            //throw new Parser.Failure(e.getMessage(), location);
        } finally {
            try {pdfDoc.close();} catch (final IOException e) {}
        }
        pdfDoc = null;

        String[] docKeywords = null;
        if (docKeywordStr != null) {
            docKeywords = docKeywordStr.split(" |,");
        }
        if (docTitle == null) {
            docTitle = docSubject;
        }

        byte[] contentBytes;
        contentBytes = UTF8.getBytes(writer.toString());

        // clear resources in pdfbox. they say that is resolved but it's not. see:
        // https://issues.apache.org/jira/browse/PDFBOX-313
        // https://issues.apache.org/jira/browse/PDFBOX-351
        // https://issues.apache.org/jira/browse/PDFBOX-441
View Full Code Here

        SUPPORTED_MIME_TYPES.add("application/vnd.openxmlformats-officedocument.spreadsheetml.template");
    }
   
    private Document[] parse(final MultiProtocolURI location, final String mimeType, final String charset, final File dest) throws Parser.Failure, InterruptedException {
       
        CharBuffer writer = null;
        try {         
            String docDescription = null;
            String docKeywordStr  = null;
            String docShortTitle  = null;
            String docLongTitle   = null;
            String docAuthor      = null;
            String docLanguage    = null;
           
            // opening the file as zip file
            final ZipFile zipFile= new ZipFile(dest);
            final Enumeration<? extends ZipEntry> zipEnum = zipFile.entries();
            final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
           
            // looping through all containing files
            while (zipEnum.hasMoreElements()) {
               
                // get next zip file entry
                final ZipEntry zipEntry= zipEnum.nextElement();
                final String entryName = zipEntry.getName();
               
                // content.xml contains the document content in xml format
                if (entryName.equals("word/document.xml")
                  || entryName.startsWith("ppt/slides/slide")
                  || entryName.startsWith("xl/worksheets/sheet")) {
                   
                    // create a writer for output
                    writer = new CharBuffer();
                   
                    // extract data
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    saxParser.parse(zipFileEntryStream, new ODContentHandler(writer));
               
                    // close readers and writers
                    zipFileEntryStream.close();
                    writer.close();
                   
                } else if (entryName.equals("docProps/core.xml")) {
                    //  meta.xml contains metadata about the document
                    final InputStream zipFileEntryStream = zipFile.getInputStream(zipEntry);
                    final SAXParser saxParser = saxParserFactory.newSAXParser();
                    final ODMetaHandler metaData = new ODMetaHandler();
                    saxParser.parse(zipFileEntryStream, metaData);
                    docDescription = metaData.getDescription();
                    docKeywordStr  = metaData.getKeyword();
                    docShortTitle  = metaData.getTitle();
                    docLongTitle   = metaData.getSubject();
                    docAuthor      = metaData.getCreator();
                    docLanguage    = metaData.getLanguage();
                }
            }
           
            // make the languages set
            final Set<String> languages = new HashSet<String>(1);
            if (docLanguage != null && docLanguage.length() == 0)
          languages.add(docLanguage);
           
            // if there is no title availabe we generate one
            if ((docLongTitle == null || docLongTitle.length() == 0) && (docShortTitle != null)) {
                    docLongTitle = docShortTitle;
            }           
        
            // split the keywords
            String[] docKeywords = null;
            if (docKeywordStr != null) docKeywords = docKeywordStr.split(" |,");
           
            // create the parser document
            Document[] docs = null;
            final byte[] contentBytes = UTF8.getBytes(writer.toString());
            docs = new Document[]{new Document(
                    location,
                    mimeType,
                    "UTF-8",
                    this,
                    languages,
                    docKeywords,
                    docLongTitle,
                    docAuthor,
                    "",
                    null,
                    docDescription,
                    0.0f, 0.0f,
                    contentBytes,
                    null,
                    null,
                    null,
                    false)};
            return docs;
        } catch (final Exception e) {           
            if (e instanceof InterruptedException) throw (InterruptedException) e;
            if (e instanceof Parser.Failure) throw (Parser.Failure) e;
           
            // close the writer
            if (writer != null) try {
                writer.close();
            } catch (final Exception ex) {/* ignore this */}

            Log.logException(e);
            throw new Parser.Failure("Unexpected error while parsing odt file. " + e.getMessage(),location);
        }
View Full Code Here

      if(args.length < 1 || args[0].contains("help")) {
    System.out.println(HELP);

      } else if(args[0].equals("--sign") && args.length==3) {
    CryptoLib cl = new CryptoLib();
    CharBuffer privKeyBuffer = new CharBuffer(new File(args[1]));
    byte[] privKeyByteBuffer = Base64Order.standardCoder.decode(privKeyBuffer.toString());
    PrivateKey privKey = cl.getPrivateKeyFromBytes(privKeyByteBuffer);

    FileInputStream dataStream = new FileInputStream(args[2]);

    byte[] signBuffer = cl.getSignature(privKey, dataStream);
    FileWriter signFile = new FileWriter(args[2] + ".sig");
    signFile.write(Base64Order.standardCoder.encode(signBuffer));
    signFile.close();
      } else if(args[0].equals("--verify") && args.length==3) {
    CryptoLib cl = new CryptoLib();
    CharBuffer pubKeyBuffer = new CharBuffer(new File(args[1]));
    byte[] pubKeyByteBuffer = Base64Order.standardCoder.decode(pubKeyBuffer.toString().trim());
    PublicKey pubKey = cl.getPublicKeyFromBytes(pubKeyByteBuffer);

    FileInputStream dataStream = new FileInputStream(args[2]);

    CharBuffer signBuffer = new CharBuffer(new File(args[2] + ".sig"));
    byte[] signByteBuffer = Base64Order.standardCoder.decode(signBuffer.toString().trim());
    if(cl.verifySignature(pubKey, dataStream, signByteBuffer)) {
        System.out.println("Signature OK!");
    } else {
        System.out.println("Signature FALSE!!!!!!!!!!!");
        System.exit(1);
View Full Code Here

            final boolean passbyIfBinarySuspect
    ) {
        this.outStream     = outStream;
        this.scraper       = scraper;
        this.transformer   = transformer;
        this.buffer        = new CharBuffer(1024);
        this.filterTag     = null;
        this.filterOpts    = null;
        this.filterCont    = null;
        this.inSingleQuote = false;
        this.inDoubleQuote = false;
View Full Code Here

            this.out = new OutputStreamWriter(this.outStream,(charSet == null)?Charset.defaultCharset():charSet);
        }
    }

    public static char[] genTag0raw(final String tagname, final boolean opening, final char[] tagopts) {
            final CharBuffer bb = new CharBuffer(tagname.length() + tagopts.length + 3);
            bb.append((int)'<');
            if (!opening) {
                bb.append((int)'/');
            }
            bb.append(tagname);
            if (tagopts.length > 0) {
//              if (tagopts[0] == (byte) 32)
                bb.append(tagopts);
//              else bb.append((byte) 32).append(tagopts);
            }
            bb.append((int)'>');
            final char[] result = bb.getChars();
            try {
                bb.close();
            } catch (final IOException e) {
                Log.logException(e);
            }
            return result;
    }
View Full Code Here

            }
            return result;
    }

    public static char[] genTag1raw(final String tagname, final char[] tagopts, final char[] text) {
            final CharBuffer bb = new CharBuffer(2 * tagname.length() + tagopts.length + text.length + 5);
            bb.append((int)'<').append(tagname);
            if (tagopts.length > 0) {
//              if (tagopts[0] == (byte) 32)
                bb.append(tagopts);
//              else bb.append((byte) 32).append(tagopts);
            }
            bb.append((int)'>');
            bb.append(text);
            bb.append((int)'<').append((int)'/').append(tagname).append((int)'>');
            final char[] result = bb.getChars();
            try {
                bb.close();
            } catch (final IOException e) {
                Log.logException(e);
            }
            return result;
    }
View Full Code Here

            return result;
    }

    public static char[] genTag0(final String tagname, final Properties tagopts, final char quotechar) {
            final char[] tagoptsx = (tagopts.isEmpty()) ? null : genOpts(tagopts, quotechar);
            final CharBuffer bb = new CharBuffer(tagname.length() + ((tagoptsx == null) ? 0 : (tagoptsx.length + 1)) + tagname.length() + 2);
            bb.append((int)'<').append(tagname);
            if (tagoptsx != null) {
                bb.append(32);
                bb.append(tagoptsx);
            }
            bb.append((int)'>');
            final char[] result = bb.getChars();
            try {
                bb.close();
            } catch (final IOException e) {
                Log.logException(e);
            }
            return result;
    }
View Full Code Here

            return result;
    }

    public static char[] genTag1(final String tagname, final Properties tagopts, final char[] text, final char quotechar) {
            final char[] gt0 = genTag0(tagname, tagopts, quotechar);
            final CharBuffer cb = new CharBuffer(gt0, gt0.length + text.length + tagname.length() + 3);
            cb.append(text).append((int)'<').append((int)'/').append(tagname).append((int)'>');
            final char[] result = cb.getChars();
            try {
                cb.close();
            } catch (final IOException e) {
                Log.logException(e);
            }
            return result;
    }
View Full Code Here

TOP

Related Classes of net.yacy.kelondro.io.CharBuffer

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.