当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils.toByteArray方法代码示例

本文整理汇总了Java中org.apache.tika.io.IOUtils.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.toByteArray方法的具体用法?Java IOUtils.toByteArray怎么用?Java IOUtils.toByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tika.io.IOUtils的用法示例。


在下文中一共展示了IOUtils.toByteArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseEmbedded

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
/**
 * Processa i contenuti
 *
 * @since 1.1: aggiunto il trattamento dei TIFF
 * @param stream stream binario del contenuto
 * @param handler handler
 * @param metadata metadati del documento
 * @param outputHtml necessario per l'override del metodo ma mai usato
 * @throws SAXException eccezione
 * @throws IOException Eccezione di input/output
 */
@Override
public void parseEmbedded(InputStream stream, org.xml.sax.ContentHandler handler, Metadata metadata, boolean outputHtml) throws SAXException, IOException {
    String name = "Content" + fileCount++;
    MediaType contentType = detector.detect(stream, metadata);
    if (contentType != null) {
        try {
            name += config.getMimeRepository().forName(contentType.toString()).getExtension();
        } catch (MimeTypeException e) {
            LogGui.printException(e);
        }
    }
    byte[] bytes = IOUtils.toByteArray(stream);
    embedded.put(name, bytes);
    if (name.toLowerCase().endsWith("jpg") || name.toLowerCase().endsWith("tiff") || name.toLowerCase().endsWith("tif") || name.toLowerCase().endsWith("png") || name.toLowerCase().endsWith("gif")) {

        BufferedImage pl = ImageIO.read(new ByteArrayInputStream(bytes));
        if (pl != null) {
            if ((pl.getWidth() > 32 && pl.getHeight() > 32)) //No Icone
            {
                embeddedImages.put(name, pl);
            }
        }

    }
}
 
开发者ID:fiohol,项目名称:theSemProject,代码行数:37,代码来源:SemEmbeddedDocumentsExtractor.java

示例2: convertInputStreamToDataURI

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
private URI convertInputStreamToDataURI(InputStream inputStream, String mimeType) throws IOException {
    byte[] byteArrayPhoto = IOUtils.toByteArray(inputStream);
    String base64Photo = DatatypeConverter.printBase64Binary(byteArrayPhoto);

    StringBuilder uriStringBuilder = new StringBuilder();
    uriStringBuilder.append(DATA).append(mimeType)
            .append(BASE64).append(base64Photo);

    URI retDataUri;
    try {
        retDataUri = new URI(uriStringBuilder.toString());
    } catch (URISyntaxException e) {
        throw new SCIMDataValidationException(e.getMessage(), e);
    }
    return retDataUri;
}
 
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:17,代码来源:DataURI.java

示例3: addPicture

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
private void addPicture(TopicMap tm, Topic userTopic) {
    try {
        URL imageUrl = new URL(AbstractFBGraphExtractor.URL_ROOT + this.user.getId() + "/picture");
        String contentType = imageUrl.openConnection().getContentType();
        byte[] data = IOUtils.toByteArray(imageUrl.openStream());
        DataURL u = new DataURL(contentType, data);
        
        Topic picType = getOrCreateType(tm, "Profile Picture");
        Topic langTopic = getOrCreateTopic(tm, XTMPSI.LANG_INDEPENDENT);
        userTopic.setData(picType, langTopic, u.toExternalForm());
        
        
    } catch (IOException | TopicMapException e) {
        UserWrapper.logger.log(e);
    } 
    
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:18,代码来源:UserWrapper.java

示例4: writeOutput

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
private void writeOutput(RemoteIterator<? extends FileStatus> input) throws IOException {
    Path outPath = new Path(output);
    if (distribFs.exists(outPath)) {
        throw new IllegalArgumentException("Output file already exists, Not overwriting it:" + output);
    }

    Writer writer = SequenceFile.createWriter(distribFs.getConf(),
            Writer.file(outPath),
            Writer.keyClass(Text.class),
            Writer.valueClass(BytesWritable.class),
            Writer.compression(SequenceFile.CompressionType.RECORD));
    Text key = new Text();
    BytesWritable value = new BytesWritable();
    long skipped = 0;
    long copied = 0;
    while (input.hasNext()) {
        FileStatus next = input.next();
        if (filter(next)) {
            key.set(next.getPath().toString());
            FSDataInputStream stream = localFs.open(next.getPath());
            //CAUTION : this could cause memory overflow
            byte[] bytes = IOUtils.toByteArray(stream);
            value.set(bytes, 0, bytes.length);
            writer.append(key, value);
            copied++;
        } else {
            skipped++;
        }
    }
    writer.close();
    System.out.println("Files copied ::" + copied);
    System.out.println("Files skipped ::" + skipped);
}
 
开发者ID:thammegowda,项目名称:tika-dl4j-spark-imgrec,代码行数:34,代码来源:Local2SeqFile.java

示例5: parse

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
public void parse(
        InputStream stream, ContentHandler handler,
        Metadata metadata, ParseContext context)
        throws IOException, SAXException, TikaException {

    byte[] bytes = IOUtils.toByteArray(stream);
    String encoded = Base64.getEncoder().encodeToString(bytes);
    embedded.put(metadata.get("resourceName"),encoded);


}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:DHFExport.java

示例6: getFaxImage

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
private byte[] getFaxImage(String path) throws UnsuccessfulStatusCodeException {

        Response response = null;
        byte[] responseBytes = null;
        try {

            URI uri = UriBuilder
                    .fromPath(path)
                    .host(hostname)
                    .scheme(scheme)
                    .port(port)
                    .build();

            response = client.target(uri).request().get();
            if (response.getStatus() == 200) {
                InputStream inputStream = response.readEntity(InputStream.class);
                responseBytes = IOUtils.toByteArray(inputStream);
                inputStream.close();
            } else {
                throw new UnsuccessfulStatusCodeException("Unsuccessful response from API", response.getStatus());
            }
        } catch (IOException e) {
            log.error("Exception occurred while getting fax image", e);
        } finally {
            close(response);
        }

        return responseBytes;
    }
 
开发者ID:interfax,项目名称:interfax-java,代码行数:30,代码来源:DefaultInterFAXClient.java

示例7: testParseArchive

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testParseArchive() throws Exception {
  byte[] zipBody = IOUtils.toByteArray(TikaInputStream.get(getClass().getResource("test-documents.zip")));
  LWSolrDocument doc = new LWSolrDocument();
  doc.setId("test-documents.zip");
  doc.setContent(zipBody);

  LWDocument[] docs = new TikaParsing().tikaParsing(doc);

  // validations
  Set<String> expectedDocs = new HashSet<>();
  expectedDocs.add("test-documents.zip#testEXCEL.xls");
  expectedDocs.add("test-documents.zip#testHTML.html");
  expectedDocs.add("test-documents.zip#testOpenOffice2.odt");
  expectedDocs.add("test-documents.zip#testPDF.pdf");
  expectedDocs.add("test-documents.zip#testPPT.ppt");
  expectedDocs.add("test-documents.zip#testRTF.rtf");
  expectedDocs.add("test-documents.zip#testTXT.txt");
  expectedDocs.add("test-documents.zip#testWORD.doc");
  expectedDocs.add("test-documents.zip#testXML.xml");

  Assert.assertEquals("Invalid parsed documents number", 10, docs.length);
  for (int index = 0; index < 9; index++) {
    Assert.assertTrue("Invalid parsed document", expectedDocs.contains(docs[index].getId()));
  }
  Assert.assertTrue("Invalid parsed document",
    docs[9].getId().startsWith("test-documents.zip#"));// document representing the zip file
  Assert.assertEquals("Invalid parsed document", docs[9].getFirstFieldValue("Content-Type"), "application/zip");
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:30,代码来源:TikaParsingTest.java

示例8: getResponseBodyAsBytes

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
@Override
public byte[] getResponseBodyAsBytes() throws IOException
{
    if (bodyBytes == null)
    {
        bodyBytes = IOUtils.toByteArray(bodyStream);
        bodyStream.close();
        
        // Build a new stream version in case they also want that
        bodyStream = new ByteArrayInputStream(bodyBytes);
    }
    return bodyBytes;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:14,代码来源:RemoteConnectorResponseImpl.java

示例9: uploadDocument

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
@Override
public APIResponse uploadDocument(final File fileToUpload, final Optional<DocumentUploadSessionOptions> options) {

    Response response = null;
    APIResponse apiResponse = new APIResponse();

    try {

        // create document upload session
        URI outboundDocumentsUri = getOutboundDocumentsUri(fileToUpload, options);

        WebTarget target = client.target(outboundDocumentsUri);
        response = target.request().header("Content-Length", 0).post(null);

        apiResponse = new APIResponse();
        apiResponse.setStatusCode(response.getStatus());
        copyHeadersToAPIResponse(response, apiResponse);

        if (response.hasEntity())
            apiResponse.setResponseBody(response.readEntity(String.class));

        // upload chunks
        if (apiResponse.getStatusCode() == Response.Status.CREATED.getStatusCode()) {

            String uploadChunkToDocumentEndpoint = URI
                                                .create(apiResponse.getHeaders().get("Location").get(0).toString())
                                                .getPath();

            InputStream inputStream = new FileInputStream(fileToUpload);
            byte[] bytes = IOUtils.toByteArray(inputStream);
            int chunkSize = 1024*1024;
            byte[][] chunks = ArrayUtil.chunkArray(bytes, chunkSize);
            int bytesUploaded = 0;
            APIResponse chunkUploadResponses = new APIResponse();
            for (int i=0; i<chunks.length; i++) {

                boolean lastChunk = false;
                if (i == chunks.length-1) {
                    lastChunk = true;
                }
                chunkUploadResponses = uploadChunk(uploadChunkToDocumentEndpoint, chunks[i], bytesUploaded, bytesUploaded+chunks[i].length-1, lastChunk);
                bytesUploaded += chunks[i].length;
            }
            apiResponse.setStatusCode(chunkUploadResponses.getStatusCode());
        }
    } catch (Exception e) {
        log.error("Exception occurred while uplading document", e);
        apiResponse.setStatusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    } finally {
        close(response);
    }

    return apiResponse;
}
 
开发者ID:interfax,项目名称:interfax-java,代码行数:55,代码来源:DefaultInterFAXClient.java


注:本文中的org.apache.tika.io.IOUtils.toByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。