Package net.yacy.kelondro.io

Examples of net.yacy.kelondro.io.CharBuffer


    }

    // a helper method for pretty-printing of properties for html tags
    public static char[] genOpts(final Properties prop, final char quotechar) {
            final Enumeration<?> e = prop.propertyNames();
            final CharBuffer bb = new CharBuffer(prop.size() * 40);
            String key;
            while (e.hasMoreElements()) {
                key = (String) e.nextElement();
                bb.append(32).append(key).append((int)'=').append((int)quotechar);
                bb.append(prop.getProperty(key));
                bb.append((int)quotechar);
            }
            final char[] result;
            if (bb.length() > 0)
                result = bb.getChars(1);
            else
                result = bb.getChars();
            try {
                bb.close();
            } catch (final IOException ex) {
                Log.logException(ex);
            }
            return result;
    }
View Full Code Here


            // we have a new tag
            if (opening) {
                if ((this.scraper != null) && (this.scraper.isTag0(tag))) {
                    // this single tag is collected at once here
                    final CharBuffer charBuffer = new CharBuffer(content);
                    this.scraper.scrapeTag0(tag, charBuffer.propParser());
                    try {
                        charBuffer.close();
                    } catch (final IOException e) {
                        // TODO Auto-generated catch block
                        Log.logException(e);
                    }
                }
                if ((this.transformer != null) && (this.transformer.isTag0(tag))) {
                    // this single tag is collected at once here
                    final CharBuffer scb = new CharBuffer(content);
                    try {
                        return this.transformer.transformTag0(tag, scb.propParser(), quotechar);
                    } finally {
                        try {
                            scb.close();
                        } catch (final IOException e) {
                            Log.logException(e);
                        }
                    }
                } else if (((this.scraper != null) && (this.scraper.isTag1(tag))) ||
                           ((this.transformer != null) && (this.transformer.isTag1(tag)))) {
                    // ok, start collecting
                    this.filterTag = tag;
                    final CharBuffer scb = new CharBuffer(content);
                    this.filterOpts = scb.propParser();
                    try {
                        scb.close();
                    } catch (final IOException e) {
                        Log.logException(e);
                    }
                    if (this.filterCont == null) this.filterCont = new CharBuffer(Math.max(100, content.length)); else this.filterCont.reset();
                    return new char[0];
                } else {
                     // we ignore that thing and return it again
                     return genTag0raw(tag, true, content);
                }
View Full Code Here

    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

        this.headlines = new ArrayList[6];
        for (int i = 0; i < this.headlines.length; i++) this.headlines[i] = new ArrayList<String>();
        this.bold = new ClusteredScoreMap<String>();
        this.italic = new ClusteredScoreMap<String>();
        this.li = new ArrayList<String>();
        this.content = new CharBuffer(1024);
        this.htmlFilterEventListeners = new EventListenerList();
        this.lon = 0.0f;
        this.lat = 0.0f;
        this.evaluationScores.match(Element.url, root.toNormalform(false, false));
        this.canonical = null;
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 String dc_creator,
            final String dc_subject,
            final String dc_publisher,
            final float lat,
            final float lon) {
        final CharBuffer s = new CharBuffer(360);
        s.append(url.toNormalform(false, true)).append(10);
        s.append(dc_title).append(10);
        s.append(dc_creator.length() > 80 ? dc_creator.substring(0, 80) : dc_creator).append(10);
        s.append(dc_subject.length() > 120 ? dc_subject.substring(0, 120) : dc_subject).append(10);
        s.append(dc_publisher).append(10);
        if (lon == 0.0f && lat == 0.0f) s.append(10); else s.append(Float.toString(lat)).append(',').append(Float.toString(lon)).append(10);
    return UTF8.getBytes(s.toString());
    }
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

   
    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());
        }
        final CharBuffer writer = new CharBuffer();
        try {
            // create a writer for output
            final PDFTextStripper  stripper = new PDFTextStripper();
            // we start the pdf parsing in a separate thread to ensure that it can be terminated
            final Thread t = new Thread() {
                public void run() {
                    try {
                        stripper.writeText(pdfDoc, writer); // may throw a NPE
                    } catch (final Throwable e) {}
                }
            };
            t.start();
            t.join(3000);
            if (t.isAlive()) t.interrupt();
            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) {}
        }

        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

    }

    public boolean checkSignature() {
        if(this.releaseFile != null) {
            try {
                final CharBuffer signBuffer = new CharBuffer(getSignatureFile());
                final byte[] signByteBuffer = Base64Order.standardCoder.decode(signBuffer.toString().trim());
                final CryptoLib cl = new CryptoLib();
                for(final yacyUpdateLocation updateLocation : latestReleaseLocations) {
                    try {
                        if(cl.verifySignature(updateLocation.getPublicKey(),
                            new FileInputStream(this.releaseFile), signByteBuffer)) {
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.