001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.converter.jaxb;
018
019 import java.io.FilterReader;
020 import java.io.IOException;
021 import java.io.Reader;
022
023 /**
024 * This FilterReader will filter out the non-XML characters, see
025 * {@link NonXmlCharFilterer} for details.
026 */
027 public class NonXmlFilterReader extends FilterReader {
028 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
029
030 protected NonXmlFilterReader(Reader in) {
031 super(in);
032 }
033
034 /**
035 * Reads characters into a portion of an array.
036 *
037 * @exception IOException
038 * If an I/O error occurs
039 */
040 public int read(char cbuf[], int off, int len) throws IOException {
041 int read = in.read(cbuf, off, len);
042 if (read > 0) {
043 nonXmlCharFilterer.filter(cbuf, off, read);
044 }
045 return read;
046 }
047
048 }