Examples of CharBuffer


Examples of net.yacy.kelondro.io.CharBuffer

   
    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

Examples of net.yacy.kelondro.io.CharBuffer

        }

        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

Examples of net.yacy.kelondro.io.CharBuffer

        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

Examples of net.yacy.kelondro.io.CharBuffer

      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

Examples of org.ajax4jsf.io.CharBuffer

            stream.write(i);
        }

        assertEquals(255, stream.getLength());

        CharBuffer firstBuffer = stream.getFirstBuffer();

        assertNull(firstBuffer.getNext());
        assertNull(firstBuffer.getPrevious());
        stream.reset();
        assertEquals(0, stream.getLength());
        firstBuffer = stream.getFirstBuffer();
        assertEquals(0, firstBuffer.getUsedSize());
        assertNull(firstBuffer.getNext());
        assertNull(firstBuffer.getPrevious());
    }
View Full Code Here

Examples of org.gatein.common.text.CharBuffer

   protected String internalToString(Locale locale) throws ConversionException
   {
      try
      {
         CharBuffer buffer = new CharBuffer();
         internalWrite(locale, buffer);
         return buffer.asString();
      }
      catch (IOException e)
      {
         throw new UndeclaredIOException(e);
      }
View Full Code Here

Examples of org.gatein.pc.portlet.impl.jsr168.CharBuffer

    }
   }

   public PrintWriter getWriter() throws IOException
   {
      CharBuffer charBuffer;
      if (buffer != null)
      {
         if (buffer instanceof CharBuffer)
         {
            charBuffer = (CharBuffer)buffer;
         }
         else
         {
            throw new IllegalStateException("The method getPortletOutputStream() was already called");
         }
      }
      else
      {
         buffer = charBuffer = new CharBuffer();
      }
      return charBuffer.getWriter();
   }
View Full Code Here

Examples of org.jboss.portal.common.text.CharBuffer

      // Map result = Collections.EMPTY_MAP;

      ParameterMap parameterMap = new ParameterMap();

      String encodedName = null;
      CharBuffer buffer = new CharBuffer(50);


      int pos = 0;
      int len = queryString.length();
      int state = LOOKUP;
      while (true)
      {
         char c;
         if (pos < len)
         {
            c = queryString.charAt(pos++);
         }
         else if (pos == len)
         {
            c = '&';
            pos++;
         }
         else
         {
            break;
         }

         //
         switch(state)
         {
            case LOOKUP:
               if (c == '&')
               {
                  // Do nothing
               }
               else if (c == '=')
               {
                  state = INVALID_CHUNK;
               }
               else
               {
                  state = PARAM_NAME;
                  buffer.append(c);
               }
               break;
            case PARAM_NAME:
               if (c == '&')
               {
                  String tmp = buffer.asString();

                  //
                  try
                  {
                     parameterDecoder.encode(tmp, buffer);
                     append(parameterMap, buffer.asString(false), "");
                  }
                  catch (EncodingException e)
                  {
                     log.debug("Could not decode parameter name " + tmp, e);
                  }

                  //
                  buffer.reset();
                  state = LOOKUP;
               }
               else if (c == '=')
               {
                  encodedName = buffer.asString();
                  buffer.reset();
                  state = PARAM_VALUE;
               }
               else
               {
                  buffer.append(c);
               }
               break;
            case PARAM_VALUE:
               if (c == '&')
               {

                  //
                  try
                  {
                     // Save value
                     String encodedValue = buffer.asString();

                     // Decode parameter name
                     parameterDecoder.encode(encodedName, buffer);
                     String name = buffer.asString(false);

                     // Now decode parameter value
                     try
                     {
                        buffer.reset();
                        parameterDecoder.encode(encodedValue, buffer);
                        String value = buffer.asString();
                        append(parameterMap, name, value);
                     }
                     catch (EncodingException e)
                     {
                        log.debug("Could not decode parameter value " + encodedValue, e);
                     }
                  }
                  catch (EncodingException e)
                  {
                     log.debug("Could not decode parameter name " + encodedName, e);
                  }

                  //
                  buffer.reset();
                  state = LOOKUP;
               }
               else
               {
                  buffer.append(c);
               }
               break;
            case INVALID_CHUNK:
               if (c == '&')
               {
View Full Code Here

Examples of org.jostraca.comp.antlr.CharBuffer

  private boolean iDirectiveNameSeen = false;
public DirectiveAntlrLexer(InputStream in) {
  this(new ByteBuffer(in));
}
public DirectiveAntlrLexer(Reader in) {
  this(new CharBuffer(in));
}
View Full Code Here

Examples of org.teavm.classlib.impl.charset.CharBuffer

        return fillBuffer() ? outBuffer.get() : -1;
    }

    @Override
    public int read(char[] cbuf, int off, int len) throws TIOException {
        CharBuffer wrapBuffer = new CharBuffer(cbuf, off, off + len);
        while (!wrapBuffer.end()) {
            wrapBuffer.put(outBuffer);
            if (outBuffer.end() && !fillBuffer()) {
                break;
            }
        }
        return wrapBuffer.position() - off;
    }
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.