Coverage Report - org.apache.myfaces.view.facelets.util.FastWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
FastWriter
0%
0/33
0%
0/4
1.25
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with 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,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.view.facelets.util;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.io.Writer;
 23  
 
 24  
 /**
 25  
  * @author Jacob Hookom
 26  
  * @version $Id$
 27  
  */
 28  
 public final class FastWriter extends Writer
 29  
 {
 30  
 
 31  
     private char[] buff;
 32  
     private int size;
 33  
 
 34  
     public FastWriter()
 35  
     {
 36  0
         this(1024);
 37  0
     }
 38  
 
 39  
     public FastWriter(int initialSize)
 40  0
     {
 41  0
         if (initialSize < 0)
 42  
         {
 43  0
             throw new IllegalArgumentException("Initial Size cannot be less than 0");
 44  
         }
 45  0
         this.buff = new char[initialSize];
 46  0
     }
 47  
 
 48  
     public void close() throws IOException
 49  
     {
 50  
         // do nothing
 51  0
     }
 52  
 
 53  
     public void flush() throws IOException
 54  
     {
 55  
         // do nothing
 56  0
     }
 57  
 
 58  
     private void overflow(int len)
 59  
     {
 60  0
         if (this.size + len > this.buff.length)
 61  
         {
 62  0
             char[] next = new char[(this.size + len) * 2];
 63  0
             System.arraycopy(this.buff, 0, next, 0, this.size);
 64  0
             this.buff = next;
 65  
         }
 66  0
     }
 67  
 
 68  
     public void write(char[] cbuf, int off, int len) throws IOException
 69  
     {
 70  0
         overflow(len);
 71  0
         System.arraycopy(cbuf, off, this.buff, this.size, len);
 72  0
         this.size += len;
 73  0
     }
 74  
 
 75  
     public void write(char[] cbuf) throws IOException
 76  
     {
 77  0
         this.write(cbuf, 0, cbuf.length);
 78  0
     }
 79  
 
 80  
     public void write(int c) throws IOException
 81  
     {
 82  0
         this.overflow(1);
 83  0
         this.buff[this.size] = (char) c;
 84  0
         this.size++;
 85  0
     }
 86  
 
 87  
     public void write(String str, int off, int len) throws IOException
 88  
     {
 89  0
         overflow(len);
 90  0
         str.getChars(off, off+len, this.buff, size);
 91  0
         this.size += len;
 92  0
     }
 93  
 
 94  
     public void write(String str) throws IOException
 95  
     {
 96  0
         this.write(str, 0, str.length());
 97  0
     }
 98  
 
 99  
     public void reset()
 100  
     {
 101  0
         this.size = 0;
 102  0
     }
 103  
 
 104  
     public String toString()
 105  
     {
 106  0
         return new String(this.buff, 0, this.size);
 107  
     }
 108  
 }