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


Java IOHelper类代码示例

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


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

示例1: getAtlasContextFactory

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
private synchronized AtlasContextFactory getAtlasContextFactory() throws Exception {
    if (atlasContextFactory == null) {

        Properties properties = new Properties();

        // load the properties from property file which may overrides the default ones
        if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
            InputStream reader = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(),
                    getPropertiesFile());
            try {
                properties.load(reader);
                log.info("Loaded the Atlas properties file " + getPropertiesFile());
            } finally {
                IOHelper.close(reader, getPropertiesFile(), log);
            }
            log.debug("Initializing AtlasContextFactory with properties {}", properties);
            atlasContextFactory = new DefaultAtlasContextFactory(properties);
        } else {
            atlasContextFactory = DefaultAtlasContextFactory.getInstance();
        }
    }
    return atlasContextFactory;
}
 
开发者ID:atlasmap,项目名称:camel-atlasmap,代码行数:24,代码来源:AtlasEndpoint.java

示例2: roundtripWithBinaryAttachments

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Test
public void roundtripWithBinaryAttachments() throws IOException {
    String attContentType = "application/binary";
    byte[] attText = {0, 1, 2, 3, 4, 5, 6, 7};
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    DataSource ds = new ByteArrayDataSource(attText, attContentType);
    in.addAttachment(attFileName, new DataHandler(ds));
    Exchange result = template.send("direct:roundtrip", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertArrayEquals(attText, os.toByteArray());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MimeMultipartDataFormatTest.java

示例3: readLine

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
private String readLine(InputStream is) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    try {
        int c;
        do {
            c = is.read();
            if (c == '\n') {
                return bytes.toString();
            }
            bytes.write(c);
        } while (c != -1);
    } finally {
        IOHelper.close(bytes);
    }

    String message = "[scp] Unexpected end of stream";
    throw new IOException(message);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:ScpOperations.java

示例4: process

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception { //NOPMD
    InputStream stream = exchange.getIn().getMandatoryBody(InputStream.class);
    try {
        // lets setup the out message before we invoke the signing
        // so that it can mutate it if necessary
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        verify(stream, out);
        clearMessageHeaders(out);
    } catch (Exception e) {
        // remove OUT message, as an exception occurred
        exchange.setOut(null);
        throw e;
    } finally {
        IOHelper.close(stream, "input stream");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:XmlVerifierProcessor.java

示例5: testMapWriteTextWithKey

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Test
public void testMapWriteTextWithKey() throws Exception {
    if (!canTest()) {
        return;
    }
    String txtKey = "THEKEY";
    String txtValue = "CIAO MONDO !";
    template.sendBodyAndHeader("direct:write_text3", txtValue, "KEY", txtKey);

    Configuration conf = new Configuration();
    Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-text3");
    FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
    MapFile.Reader reader = new MapFile.Reader(fs1, "file:///" + TEMP_DIR.toUri() + "/test-camel-text3", conf);
    Text key = (Text) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
    Text value = (Text) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(key, value);
    assertEquals(key.toString(), txtKey);
    assertEquals(value.toString(), txtValue);

    IOHelper.close(reader);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:HdfsProducerTest.java

示例6: StreamSourceCache

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
public StreamSourceCache(StreamSource source, Exchange exchange) throws IOException {
    if (source.getInputStream() != null) {
        // set up CachedOutputStream with the properties
        CachedOutputStream cos = new CachedOutputStream(exchange);
        IOHelper.copyAndCloseInput(source.getInputStream(), cos);
        streamCache = cos.newStreamCache();
        readCache = null;
        setSystemId(source.getSystemId());
        setInputStream((InputStream) streamCache);
    } else if (source.getReader() != null) {
        String data = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, source.getReader());
        readCache = new ReaderCache(data);
        streamCache = null;
        setReader(readCache);
    } else {
        streamCache = null;
        readCache = null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:StreamSourceCache.java

示例7: testWriteFloat

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Test
public void testWriteFloat() throws Exception {
    if (!canTest()) {
        return;
    }
    float aFloat = 12.34f;
    template.sendBody("direct:write_float", aFloat);

    Configuration conf = new Configuration();
    Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-float");
    SequenceFile.Reader reader = new SequenceFile.Reader(conf, SequenceFile.Reader.file(file1));
    Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
    Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(key, value);
    float rFloat = ((FloatWritable) value).get();
    assertEquals(rFloat, aFloat, 0.0F);

    IOHelper.close(reader);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:HdfsProducerTest.java

示例8: toByteBuffer

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Converter
public static ByteBuffer toByteBuffer(File file) throws IOException {
    InputStream in = null;
    try {
        byte[] buf = new byte[(int)file.length()];
        in = IOHelper.buffered(new FileInputStream(file));
        int sizeLeft = (int)file.length();
        int offset = 0;
        while (sizeLeft > 0) {
            int readSize = in.read(buf, offset, sizeLeft);
            sizeLeft -= readSize;
            offset += readSize;
        }
        return ByteBuffer.wrap(buf);
    } finally {
        IOHelper.close(in, "Failed to close file stream: " + file.getPath(), LOG);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:NIOConverter.java

示例9: createDelimitedParser

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
public Parser createDelimitedParser(Exchange exchange) throws InvalidPayloadException, IOException {
    Reader bodyReader = exchange.getIn().getMandatoryBody(Reader.class);

    Parser parser;
    if (ObjectHelper.isEmpty(getResourceUri())) {
        parser = getParserFactory().newDelimitedParser(bodyReader, delimiter, textQualifier);
    } else {
        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), resourceUri);
        InputStreamReader reader = new InputStreamReader(is, IOHelper.getCharsetName(exchange));
        parser = getParserFactory().newDelimitedParser(reader, bodyReader, delimiter, textQualifier, ignoreFirstRecord);
    }

    if (isAllowShortLines()) {
        parser.setHandlingShortLines(true);
        parser.setIgnoreParseWarnings(true);
    }
    if (isIgnoreExtraColumns()) {
        parser.setIgnoreExtraColumns(true);
        parser.setIgnoreParseWarnings(true);
    }

    return parser;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:FlatpackEndpoint.java

示例10: testCachedStreamAccessStreamWhenExchangeOnCompletion

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
public void testCachedStreamAccessStreamWhenExchangeOnCompletion() throws Exception {
    context.start();
    CachedOutputStream cos = new CachedOutputStream(exchange, false);
    cos.write(TEST_STRING.getBytes("UTF-8"));
    
    File file = new File("target/cachedir");
    String[] files = file.list();
    assertEquals("we should have a temp file", 1, files.length);
    assertTrue("The file name should start with cos", files[0].startsWith("cos"));
    
    InputStream is = cos.getWrappedInputStream();
    exchange.getUnitOfWork().done(exchange);
    String temp = toString(is);
    assertEquals("Get a wrong stream content", temp, TEST_STRING);
    IOHelper.close(is);
    
    files = file.list();
    assertEquals("we should have a temp file", 0, files.length);
    IOHelper.close(cos);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:CachedOutputStreamTest.java

示例11: roundtripWithTextAttachmentsHeadersInline

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Test
public void roundtripWithTextAttachmentsHeadersInline() throws IOException {
    String attContentType = "text/plain";
    String attText = "Attachment Text";
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
    in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
    addAttachment(attContentType, attText, attFileName);
    Exchange result = template.send("direct:roundtripinlineheaders", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
    assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertEquals(attText, new String(os.toByteArray()));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:MimeMultipartDataFormatTest.java

示例12: roundtripWithTextAttachmentsAndBinaryContent

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Test
public void roundtripWithTextAttachmentsAndBinaryContent() throws IOException {
    String attContentType = "text/plain";
    String attText = "Attachment Text";
    String attFileName = "Attachment File Name";
    in.setBody("Body text");
    in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
    addAttachment(attContentType, attText, attFileName);
    Exchange result = template.send("direct:roundtripbinarycontent", exchange);
    Message out = result.getOut();
    assertEquals("Body text", out.getBody(String.class));
    assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
    assertEquals("iso8859-1", out.getHeader(Exchange.CONTENT_ENCODING));
    assertTrue(out.hasAttachments());
    assertEquals(1, out.getAttachmentNames().size());
    assertThat(out.getAttachmentNames(), hasItem(attFileName));
    DataHandler dh = out.getAttachment(attFileName);
    assertNotNull(dh);
    assertEquals(attContentType, dh.getContentType());
    InputStream is = dh.getInputStream();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    IOHelper.copyAndCloseInput(is, os);
    assertEquals(attText, new String(os.toByteArray()));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:MimeMultipartDataFormatTest.java

示例13: doReleaseExclusiveReadLock

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Override
protected void doReleaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange) throws Exception {
    // must call super
    super.doReleaseExclusiveReadLock(operations, file, exchange);

    FileLock lock = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), FileLock.class);
    RandomAccessFile rac = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), RandomAccessFile.class);

    String target = file.getFileName();
    if (lock != null) {
        Channel channel = lock.acquiredBy();
        try {
            lock.release();
        } finally {
            // close channel as well
            IOHelper.close(channel, "while releasing exclusive read lock for file: " + target, LOG);
            IOHelper.close(rac, "while releasing exclusive read lock for file: " + target, LOG);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:FileLockExclusiveReadLockStrategy.java

示例14: testProducer

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Test
public void testProducer() throws Exception {
    if (!canTest()) {
        return;
    }
    template.sendBody("direct:start1", "PAPPO");

    Configuration conf = new Configuration();
    Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel1");
    SequenceFile.Reader reader = new SequenceFile.Reader(conf, SequenceFile.Reader.file(file1));
    Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
    Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(key, value);
    assertEquals("PAPPO", value.toString());

    IOHelper.close(reader);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:HdfsProducerTest.java

示例15: createRouteBuilder

import org.apache.camel.util.IOHelper; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
           
            from("jetty:http://localhost:{{port}}/test?matchOnUriPrefix=true&chunked=false")
                .to("http://localhost:{{port2}}/other?bridgeEndpoint=true");
            
            from("jetty:http://localhost:{{port2}}/other").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "image/jpeg");
                    CachedOutputStream stream = new CachedOutputStream(exchange);
                    stream.write("This is hello world.".getBytes());
                    exchange.getOut().setBody(stream.getInputStream());
                    IOHelper.close(stream);
                }
            });
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:JettyChuckedFalseTest.java


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