• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Converter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: genericFileToInputStream

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static InputStream genericFileToInputStream(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException {
    if (file.getFile() instanceof File) {
        // prefer to use a file input stream if its a java.io.File
        File f = (File) file.getFile();
        // the file must exists
        if (f.exists()) {
            // read the file using the specified charset
            String charset = file.getCharset();
            if (charset != null) {
                LOG.debug("Read file {} with charset {}", f, file.getCharset());
            } else {
                LOG.debug("Read file {} (no charset)", f);
            }
            return IOConverter.toInputStream(f, charset);
        }
    }
    if (exchange != null) {
        // otherwise ensure the body is loaded as we want the input stream of the body
        file.getBinding().loadContent(exchange, file);
        return exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, file.getBody());
    } else {
        // should revert to fallback converter if we don't have an exchange
        return null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:GenericFileConverter.java


示例2: toClass

import org.apache.camel.Converter; //导入依赖的package包/类
/**
 * Returns the converted value, or null if the value is null
 */
@Converter
public static Class<?> toClass(Object value, Exchange exchange) {
    if (value instanceof Class) {
        return (Class<?>) value;
    } else if (value instanceof String) {
        // prefer to use class resolver API
        if (exchange != null) {
            return exchange.getContext().getClassResolver().resolveClass((String) value);
        } else {
            return ObjectHelper.loadClass((String) value);
        }
    } else {
        return null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:ObjectConverter.java


示例3: toByteBuffer

import org.apache.camel.Converter; //导入依赖的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


示例4: toList

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static List<Map<String, Object>> toList(DataSet dataSet) {
    List<Map<String, Object>> answer = new ArrayList<Map<String, Object>>();
    dataSet.goTop();

    while (dataSet.next()) {
        Map<String, Object> map = new HashMap<String, Object>();
        putValues(map, dataSet);
        answer.add(map);
    }

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:FlatpackConverter.java


示例5: toByteArray

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static byte[] toByteArray(ByteBuffer buffer) {
    buffer.mark();
    try {
        byte[] answer = new byte[buffer.remaining()];
        buffer.get(answer);
        return answer;
    } finally {
        buffer.reset();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:MinaConverter.java


示例6: sourceToCxfPayload

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static <T> CxfPayload<T> sourceToCxfPayload(Source src, Exchange exchange) {
    List<T> headers = new ArrayList<T>();
    List<Source> body = new ArrayList<Source>();
    body.add(src);
    return new CxfPayload<T>(headers, body, null);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:CxfPayloadConverter.java


示例7: toArrayList

import org.apache.camel.Converter; //导入依赖的package包/类
/**
 * Converts an {@link Iterator} to a {@link ArrayList}
 */
@Converter
public static <T> ArrayList<T> toArrayList(Iterator<T> it) {
    ArrayList<T> list = new ArrayList<T>();
    while (it.hasNext()) {
        list.add(it.next());
    }
    return list;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:CollectionConverter.java


示例8: toString

import org.apache.camel.Converter; //导入依赖的package包/类
/**
 * Converts the given JavaMail multipart to a String body, where the content-type of the multipart
 * must be text based (ie start with text). Can return null.
 */
@Converter
public static String toString(Multipart multipart) throws MessagingException, IOException {
    int size = multipart.getCount();
    for (int i = 0; i < size; i++) {
        BodyPart part = multipart.getBodyPart(i);
        if (part.getContentType().toLowerCase().startsWith("text")) {
            return part.getContent().toString();
        }
    }
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:MailConverters.java


示例9: toPayload

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static Payload toPayload(final StreamSourceCache cache, Exchange exchange) throws IOException {
    long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {
        @Override
        public InputStream getInput() throws IOException {
            return cache.getInputStream();
        }
    });
    cache.reset();
    InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
    payload.getContentMetadata().setContentLength(contentLength);
    setContentMetadata(payload, exchange);
    return payload;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:JcloudsPayloadConverter.java


示例10: toOutgoingMessage

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static OutgoingMessage toOutgoingMessage(String message, Exchange exchange) {
    if (message == null) {
        // fail fast
        return null;
    }

    Object typeObj = exchange.getIn().getHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE);
    TelegramMediaType type;
    if (typeObj instanceof String) {
        type = TelegramMediaType.valueOf((String) typeObj);
    } else {
        type = (TelegramMediaType) typeObj;
    }

    // If the message is a string, it will be converted to a OutgoingTextMessage
    if (type == null) {
        type = TelegramMediaType.TEXT;
    }

    OutgoingMessage result;

    switch (type) {
    case TEXT: {
        OutgoingTextMessage txt = new OutgoingTextMessage();
        txt.setText(message);
        result = txt;
        break;
    }
    default: {
        throw new IllegalArgumentException("Unsupported conversion from String to media type " + type);
    }
    }


    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:TelegramConverter.java


示例11: toDeleteRequest

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static DeleteRequest toDeleteRequest(String id, Exchange exchange) {
    return new DeleteRequest()
            .index(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARAM_INDEX_NAME,
                    String.class))
            .type(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARAM_INDEX_TYPE,
                    String.class)).id(id);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:ElasticsearchActionRequestConverter.java


示例12: toDOMDocument

import org.apache.camel.Converter; //导入依赖的package包/类
/**
 * Create a DOM document from the given Node.
 *
 * If the node is an document, just cast it, if the node is an root element, retrieve its
 * owner element or create a new document and import the node.
 */
@Converter
public Document toDOMDocument(final Node node) throws ParserConfigurationException, TransformerException {
    ObjectHelper.notNull(node, "node");

    // If the node is the document, just cast it
    if (node instanceof Document) {
        return (Document) node;
        // If the node is an element
    } else if (node instanceof Element) {
        Element elem = (Element) node;
        // If this is the root element, return its owner document
        if (elem.getOwnerDocument().getDocumentElement() == elem) {
            return elem.getOwnerDocument();
            // else, create a new doc and copy the element inside it
        } else {
            Document doc = createDocument();
            // import node must not occur concurrent on the same node (must be its owner)
            // so we need to synchronize on it
            synchronized (node.getOwnerDocument()) {
                doc.appendChild(doc.importNode(node, true));
            }
            return doc;
        }
        // other element types are not handled
    } else {
        throw new TransformerException("Unable to convert DOM node to a Document: " + node);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:XmlConverter.java


示例13: toByteArray

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static byte[] toByteArray(File file) throws IOException {
    InputStream is = toInputStream(file);
    try {
        return toBytes(is);
    } finally {
        IOHelper.close(is, "file", LOG);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:IOConverter.java


示例14: elementToCxfPayload

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static <T> CxfPayload<T> elementToCxfPayload(Element element, Exchange exchange) {
    List<T> headers = new ArrayList<T>();
    List<Element> body = new ArrayList<Element>();
    body.add(element);
    return new CxfPayload<T>(headers, body);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:CxfPayloadConverter.java


示例15: convertToString

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static String convertToString(ExecResult result, Exchange exchange) throws FileNotFoundException {
    // special for string, as we want an empty string if no output from stdin / stderr
    InputStream is = toInputStream(result);
    if (is != null) {
        return exchange.getContext().getTypeConverter().convertTo(String.class, exchange, is);
    } else {
        // no stdin/stdout, so return an empty string
        return "";
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:ExecResultConverter.java


示例16: toMethods

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static Method[] toMethods(String name) {
    String[] strings = name.split(",");
    List<Method> methods = new ArrayList<Method>();
    for (String string : strings) {
        methods.add(toMethod(string));
    }
    
    return methods.toArray(new Method[methods.size()]);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:RestletConverter.java


示例17: toString

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static String toString(Status status) throws ParseException {
    return new StringBuilder()
        .append(status.getCreatedAt()).append(" (").append(status.getUser().getScreenName()).append(") ")
        .append(status.getText())
        .toString();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:TwitterConverter.java


示例18: fromAnyObjectToDBObject

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static DBObject fromAnyObjectToDBObject(Object value) {
    BasicDBObject answer;
    try {
        Map<?, ?> m = OBJECT_MAPPER.convertValue(value, Map.class);
        answer = new BasicDBObject(m);
    } catch (Exception e) {
        LOG.warn("Conversion has fallen back to generic Object -> DBObject, but unable to convert type {}. Returning null.", 
                value.getClass().getCanonicalName());
        return null;
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:MongoDbBasicConverters.java


示例19: convertToByteArray

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public static byte[] convertToByteArray(ExecResult result, Exchange exchange) throws FileNotFoundException, IOException {
    InputStream stream = toInputStream(result);
    try {
        return IOUtils.toByteArray(stream);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:ExecResultConverter.java


示例20: createXMLStreamReader

import org.apache.camel.Converter; //导入依赖的package包/类
@Converter
public XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException {
    XMLInputFactory factory = getInputFactory();
    try {
        return factory.createXMLStreamReader(IOHelper.buffered(reader));
    } finally {
        returnXMLInputFactory(factory);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:StaxConverter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MavenRepositorySystemSession类代码示例发布时间:2022-05-21
下一篇:
Java LabelPeer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap