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


Java IOUtils类代码示例

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


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

示例1: getReferenceFiles

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
public List<String> getReferenceFiles(Node rootNode,String path,String searchText) throws Exception{
	List<String> referenceFiles=new ArrayList<String>();
	List<String> files=getFiles(rootNode, path);
	for(String nodePath:files){
		InputStream inputStream=repositoryService.readFile(nodePath,null);
		try {
			String content = IOUtils.toString(inputStream);
			inputStream.close();
			boolean containPath=content.contains(path);
			boolean containText=content.contains(searchText);
			if(containPath && containText){
				referenceFiles.add(nodePath);
			}
		} catch (IOException e) {
			throw new RuleException(e);
		}
	}
	return referenceFiles;
}
 
开发者ID:youseries,项目名称:urule,代码行数:20,代码来源:RepositoryRefactor.java

示例2: analyze

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
@Override
public Iterator<byte[]> analyze(CrawleableUri curi, File data, Sink sink) {
    FileInputStream fin = null;
    try {
        // First, try to get the language of the data
        Lang lang = null;
        String contentType = (String) curi.getData(HttpHeaders.CONTENT_TYPE);
        if (contentType != null) {
            lang = RDFLanguages.contentTypeToLang(contentType);
        } else {
            lang = RDFLanguages.filenameToLang(data.getName(), null);
        }
        FilterSinkRDF filtered = new FilterSinkRDF(curi, sink);
        RDFDataMgr.parse(filtered, data.getAbsolutePath(), lang);
    } catch (Exception e) {
        LOGGER.error("Exception while analyzing. Aborting.");
    } finally {
        IOUtils.closeQuietly(fin);
    }
    return collector.getUris(curi);
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:22,代码来源:RDFAnalyzer.java

示例3: 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

示例4: 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

示例5: doGetNext

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
@Override
protected void doGetNext(final JCas jCas) throws IOException, CollectionException {
	final String source = String.join(".", activeMQ.getResourceName(), endpoint);

	try {
		final Message msg = this.consumer.receive();
		if (msg instanceof TextMessage) {
			final String text = ((TextMessage) msg).getText();
			final InputStream is = IOUtils.toInputStream(text);

			this.extractor.processStream(is, source, jCas);
		} else {
			throw new IOException(String.format("Unexpected message type for message with id %1 from source %2",
					msg.getJMSMessageID(), source));
		}
	} catch (final JMSException e) {
		throw new CollectionException(e);
	}

}
 
开发者ID:dstl,项目名称:baleen,代码行数:21,代码来源:ActiveMQReader.java

示例6: detectArchiveFormat

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
private static MediaType detectArchiveFormat(byte[] prefix, int length) {
    try {
        ArchiveStreamFactory factory = new ArchiveStreamFactory();
        ArchiveInputStream ais = factory.createArchiveInputStream(
                new ByteArrayInputStream(prefix, 0, length));
        try {
            if ((ais instanceof TarArchiveInputStream)
                    && !TarArchiveInputStream.matches(prefix, length)) {
                // ArchiveStreamFactory is too relaxed, see COMPRESS-117
                return MediaType.OCTET_STREAM;
            } else {
                return PackageParser.getMediaType(ais);
            }
        } finally {
            IOUtils.closeQuietly(ais);
        }
    } catch (ArchiveException e) {
        return MediaType.OCTET_STREAM;
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:21,代码来源:ZipContainerDetector.java

示例7: detectOpenDocument

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
/**
 * OpenDocument files, along with EPub files, have a mimetype
 *  entry in the root of their Zip file. This entry contains the
 *  mimetype of the overall file, stored as a single string.  
 */
private static MediaType detectOpenDocument(ZipFile zip) {
    try {
        ZipArchiveEntry mimetype = zip.getEntry("mimetype");
        if (mimetype != null) {
            InputStream stream = zip.getInputStream(mimetype);
            try {
                return MediaType.parse(IOUtils.toString(stream, "UTF-8"));
            } finally {
                stream.close();
            }
        } else {
            return null;
        }
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:23,代码来源:ZipContainerDetector.java

示例8: testPolicyCreateByPost

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
@Test
public void testPolicyCreateByPost() throws Exception {
    final HttpPost objMethod = HttpPostObjMethod(POLICY_RESOURCE);
    final StringEntity input = new StringEntity(MIME_KEY + " " + MIME + " " + STORE,
                                          "UTF-8");
    input.setContentType(APPLICATION_FORM_URLENCODED);
    objMethod.setEntity(input);
    final HttpResponse response = execute(objMethod);

    final String body = IOUtils.toString(response.getEntity().getContent());
    assertEquals(body, 201, response.getStatusLine().getStatusCode());

    policyKeys.add(MIME_KEY);

    final Header[] headers = response.getHeaders("Location");
    assertNotNull(headers);
    assertEquals(1, headers.length);
    assertEquals(objMethod.getURI()
                         .toString()
                         .replace(POLICY_RESOURCE, MIME_KEY),
                 headers[0].getValue());
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-storage-policy,代码行数:23,代码来源:FedoraStoragePolicyIT.java

示例9: testGetStoragePolicy

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
@Test
public void testGetStoragePolicy() throws Exception {
    // Test no policy
    final HttpGet getMethod0 = HttpGetObjMethod(MIME_KEY);
    final HttpResponse response0 = execute(getMethod0);
    assertNotNull(response0);
    assertEquals(IOUtils.toString(response0.getEntity().getContent()),
                 404,
                 response0.getStatusLine().getStatusCode());

    // Add a policy
    testPolicyCreateByPost();

    // Test Get Storage Policy
    final HttpGet getMethod1 = HttpGetObjMethod(MIME_KEY);
    final HttpResponse response1 = execute(getMethod1);
    assertNotNull(response1);

    final String body = IOUtils.toString(response1.getEntity().getContent());
    assertEquals(body, 200, response1.getStatusLine().getStatusCode());
    assertEquals(MIME + ":" + STORE, body);
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-storage-policy,代码行数:23,代码来源:FedoraStoragePolicyIT.java

示例10: testGetStoragePolicies

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
@Test
public void testGetStoragePolicies() throws Exception {
    // Add a policy
    testPolicyCreateByPost();

    // Test Get Storage Policy
    final HttpGet getMethod1 = HttpGetObjMethod(POLICY_RESOURCE);
    final HttpResponse response1 = execute(getMethod1);
    assertNotNull(response1);

    final String body = IOUtils.toString(response1.getEntity().getContent());
    assertEquals(body, 200, response1.getStatusLine().getStatusCode());

    final StoragePolicy policy = new MimeTypeStoragePolicy(MIME, STORE);
    assertTrue("Didn't find our policy in policies!", body.contains(policy.toString()));
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-storage-policy,代码行数:17,代码来源:FedoraStoragePolicyIT.java

示例11: detect

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
/**
 * Reads an input stream and checks if it has a CSV format.
 *
 * The general contract of a detector is to not close the specified stream before returning. It is to the
 * responsibility of the caller to close it. The detector should leverage the mark/reset feature of the specified
 * {@see TikaInputStream} in order to let the stream always return the same bytes.
 *
 * @param metadata the specified TIKA {@link Metadata}
 * @param inputStream the specified input stream
 * @return either null or an CSV format
 * @throws IOException
 */
@Override
public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException {

    Format result = detectText(metadata, inputStream);

    if (result == null) {
        inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE);
        byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE];
        int n = 0;

        for (int m = inputStream.read(buffer); m != -1
                && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) {
            n += m;
        }

        inputStream.reset();
        String head = FormatUtils.readFromBuffer(buffer, 0, n);

        try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) {
            result = detectText(new Metadata(), stream);
        }
    }
    return result;
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:37,代码来源:CSVDetector.java

示例12: extractMetadata

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
private StreamParserThread extractMetadata(final InputStream stream, final Metadata metadata) {
    StreamParserThread parserThread = new StreamParserThread() {
        public void run() {
           BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
           try {
              String line;
              while ( (line = reader.readLine()) != null ) {
                 for(Pattern p : metadataPatterns.keySet()) {
                    Matcher m = p.matcher(line);
                    if(m.find()) {
                       metadata.add( metadataPatterns.get(p), m.group(1) );
                    }
                 }
              }
              this.isComplete = true;
           } catch (IOException e) {
               this.ioException = e;
           } finally {
              IOUtils.closeQuietly(reader);
              IOUtils.closeQuietly(stream);
          }
        }
    };
    parserThread.start();
    return parserThread;
}
 
开发者ID:AlfrescoLabs,项目名称:tika-ffmpeg,代码行数:27,代码来源:WaitingExternalParser.java

示例13: 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

示例14: zip

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
private File zip(File destination, String name) {
    try {
        File z = new File(Files.createTempDir(), name+".zip");
        ZipArchiveOutputStream out = ZipHelper.setupZipOutputStream(new FileOutputStream(z)); 
        for(String f : files(destination, "")) {
          out.putArchiveEntry(new ZipArchiveEntry(f));
          FileInputStream in = new FileInputStream(new File(destination, f));
          IOUtils.copy(in, out);
          in.close();
          out.closeArchiveEntry();
        }
        out.close();
        return z;
    } catch(Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:18,代码来源:HtmlZip.java

示例15: testGetDatastreamContentInputStream

import org.apache.tika.io.IOUtils; //导入依赖的package包/类
@Test
public void testGetDatastreamContentInputStream() throws Exception {
    FedoraSession session = repository.login();
    final InputStream is = new ByteArrayInputStream("asdf".getBytes());
    containerService.findOrCreate(session, "/testDatastreamServiceObject");

    binaryService.findOrCreate(session, "/testDatastreamServiceObject/" + "testDatastreamNode")
            .setContent(
                    is,
                    "application/octet-stream",
                    null,
                    null,
                    null
            );

    session.commit();
    session.expire();
    session = repository.login();
    final FedoraBinary binary =
            binaryService.findOrCreate(session,
                "/testDatastreamServiceObject/" + "testDatastreamNode");
    assertEquals("asdf", IOUtils.toString(binary.getContent(), "UTF-8"));
    session.expire();
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:25,代码来源:BinaryServiceImplIT.java


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