Coverage Report - net.sf.jmatchparser.util.split.SplitRule
 
Classes in this File Line Coverage Branch Coverage Complexity
SplitRule
25%
1/4
N/A
1
 
 1  
 /*
 2  
  * Copyright (c) 2006 - 2011 Michael Schierl
 3  
  * 
 4  
  * All rights reserved.
 5  
  * 
 6  
  * Redistribution and use in source and binary forms, with or without
 7  
  * modification, are permitted provided that the following conditions
 8  
  * are met:
 9  
  * 
 10  
  * - Redistributions of source code must retain the above copyright notice,
 11  
  *   this list of conditions and the following disclaimer.
 12  
  *   
 13  
  * - Redistributions in binary form must reproduce the above copyright
 14  
  *   notice, this list of conditions and the following disclaimer in the
 15  
  *   documentation and/or other materials provided with the distribution.
 16  
  *   
 17  
  * - Neither name of the copyright holders nor the names of its
 18  
  *   contributors may be used to endorse or promote products derived from
 19  
  *   this software without specific prior written permission.
 20  
  *   
 21  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THE CONTRIBUTORS
 22  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 23  
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 24  
  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 25  
  * HOLDERS OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 26  
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 27  
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 28  
  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 29  
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 30  
  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 31  
  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32  
  */
 33  
 package net.sf.jmatchparser.util.split;
 34  
 
 35  
 /**
 36  
  * A rule where to split a {@link SplitOutputStream}.
 37  
  */
 38  171
 public abstract class SplitRule {
 39  
 
 40  
         /**
 41  
          * Update the internal state of this split rule after some bytes have been
 42  
          * output.
 43  
          * 
 44  
          * @param data
 45  
          *            bytes that have been output
 46  
          * @param off
 47  
          *            start offset
 48  
          * @param len
 49  
          *            length
 50  
          */
 51  
         public abstract void update(byte[] data, int off, int len);
 52  
 
 53  
         /**
 54  
          * Check the given bytes whether the output stream has to be split in
 55  
          * between or after the given bytes.
 56  
          * 
 57  
          * @param data
 58  
          *            bytes that should be output
 59  
          * @param off
 60  
          *            start offset
 61  
          * @param len
 62  
          *            length
 63  
          * @return -1 if the given data does not have to be split at all, or the
 64  
          *         length after which the stream has to be split. This value can
 65  
          *         never be zero or greater than <i>len</i>.
 66  
          */
 67  
         public abstract int findSplitPos(byte[] data, int off, int len);
 68  
 
 69  
         /**
 70  
          * Update the internal state of this split rule after one byte has been
 71  
          * output. The default implementation of this method calls
 72  
          * {@link #update(byte[], int, int)} with a 1-byte byte array.
 73  
          * 
 74  
          * @param data
 75  
          *            byte that has been output
 76  
          */
 77  
         public void update(byte data) {
 78  0
                 update(new byte[] { data }, 0, 1);
 79  0
         }
 80  
 
 81  
         /**
 82  
          * Check the given byte whether the output stream has to be split after it.
 83  
          * The default implementation of this method calls
 84  
          * {@link #findSplitPos(byte[], int, int)} with a 1-byte byte array.
 85  
          * 
 86  
          * @param data
 87  
          *            byte that should be output
 88  
          * @return -1 if the given data does not have to be split at all, or 1 if
 89  
          *         the stream has to be split after this byte.
 90  
          */
 91  
         public int findSplitPos(byte data) {
 92  0
                 return findSplitPos(new byte[] { data }, 0, 1);
 93  
         }
 94  
 }