Coverage Report - org.apache.camel.converter.NIOConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
NIOConverter
18% 
N/A 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.converter;
 19  
 
 20  
 import org.apache.camel.Converter;
 21  
 
 22  
 import java.io.*;
 23  
 import java.nio.ByteBuffer;
 24  
 
 25  
 /**
 26  
  * Some core java.nio based 
 27  
  * <a href="http://activemq.apache.org/camel/type-converter.html">Type Converters</a>
 28  
  *
 29  
  * @version $Revision: 533630 $
 30  
  */
 31  
 @Converter
 32  0
 public class NIOConverter {
 33  
 
 34  
     @Converter
 35  
     public static byte[] toByteArray(ByteBuffer buffer) {
 36  0
         return buffer.array();
 37  
     }
 38  
 
 39  
     @Converter
 40  
     public static ByteBuffer toByteBuffer(byte[] data) {
 41  0
         return ByteBuffer.wrap(data);
 42  
     }
 43  
     
 44  
     @Converter
 45  
     public static ByteBuffer toByteBuffer(String value) {
 46  1
         ByteBuffer buf = ByteBuffer.allocate(value.length());
 47  1
         byte[] bytes = value.getBytes();
 48  1
         buf.put(bytes);
 49  1
         return buf;
 50  
     }
 51  
     @Converter
 52  
     public static ByteBuffer toByteBuffer(Short value) {
 53  0
         ByteBuffer buf = ByteBuffer.allocate(2);
 54  0
         buf.putShort(value);
 55  0
         return buf;
 56  
     }
 57  
     @Converter
 58  
     public static ByteBuffer toByteBuffer(Integer value) {
 59  0
         ByteBuffer buf = ByteBuffer.allocate(4);
 60  0
         buf.putInt(value);
 61  0
         return buf;
 62  
     }
 63  
     @Converter
 64  
     public static ByteBuffer toByteBuffer(Long value) {
 65  0
         ByteBuffer buf = ByteBuffer.allocate(8);
 66  0
         buf.putLong(value);
 67  0
         return buf;
 68  
     }
 69  
     @Converter
 70  
     public static ByteBuffer toByteBuffer(Float value) {
 71  0
         ByteBuffer buf = ByteBuffer.allocate(4);
 72  0
         buf.putFloat(value);
 73  0
         return buf;
 74  
     }
 75  
     @Converter
 76  
     public static ByteBuffer toByteBuffer(Double value) {
 77  0
         ByteBuffer buf = ByteBuffer.allocate(8);
 78  0
         buf.putDouble(value);
 79  0
         return buf;
 80  
     }
 81  
 }