Coverage report

  %line %branch
org.apache.commons.net.telnet.TelnetOutputStream
44% 
70% 

 1  
 /*
 2  
  * Copyright 2001-2005 The Apache Software Foundation
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.net.telnet;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.io.OutputStream;
 20  
 
 21  
 /***
 22  
  *
 23  
  * <p>
 24  
  *
 25  
  * <p>
 26  
  * <p>
 27  
  * @author Daniel F. Savarese
 28  
  ***/
 29  
 
 30  
 
 31  
 final class TelnetOutputStream extends OutputStream
 32  
 {
 33  
     private TelnetClient __client;
 34  32
     private boolean __convertCRtoCRLF = true;
 35  32
     private boolean __lastWasCR = false;
 36  
 
 37  
     TelnetOutputStream(TelnetClient client)
 38  32
     {
 39  32
         __client = client;
 40  32
     }
 41  
 
 42  
 
 43  
     /***
 44  
      * Writes a byte to the stream.
 45  
      * <p>
 46  
      * @param ch The byte to write.
 47  
      * @exception IOException If an error occurs while writing to the underlying
 48  
      *            stream.
 49  
      ***/
 50  
     public void write(int ch) throws IOException
 51  
     {
 52  
 
 53  10
         synchronized (__client)
 54  
         {
 55  10
             ch &= 0xff;
 56  
 
 57  10
             if (__client._requestedWont(TelnetOption.BINARY))
 58  
             {
 59  10
                 if (__lastWasCR)
 60  
                 {
 61  0
                     if (__convertCRtoCRLF)
 62  
                     {
 63  0
                         __client._sendByte('\n');
 64  0
                         if (ch == '\n')
 65  
                         {
 66  0
                             __lastWasCR = false;
 67  0
                             return ;
 68  
                         }
 69  
                     }
 70  0
                     else if (ch != '\n')
 71  0
                         __client._sendByte('\0');
 72  
                 }
 73  
 
 74  10
                 __lastWasCR = false;
 75  
 
 76  10
                 switch (ch)
 77  
                 {
 78  
                 case '\r':
 79  0
                     __client._sendByte('\r');
 80  0
                     __lastWasCR = true;
 81  0
                     break;
 82  
                 case TelnetCommand.IAC:
 83  0
                     __client._sendByte(TelnetCommand.IAC);
 84  0
                     __client._sendByte(TelnetCommand.IAC);
 85  0
                     break;
 86  
                 default:
 87  10
                     __client._sendByte(ch);
 88  10
                     break;
 89  
                 }
 90  
             }
 91  0
             else if (ch == TelnetCommand.IAC)
 92  
             {
 93  0
                 __client._sendByte(ch);
 94  0
                 __client._sendByte(TelnetCommand.IAC);
 95  
             }
 96  
             else
 97  0
                 __client._sendByte(ch);
 98  10
         }
 99  10
     }
 100  
 
 101  
 
 102  
     /***
 103  
      * Writes a byte array to the stream.
 104  
      * <p>
 105  
      * @param buffer  The byte array to write.
 106  
      * @exception IOException If an error occurs while writing to the underlying
 107  
      *            stream.
 108  
      ***/
 109  
     public void write(byte buffer[]) throws IOException
 110  
     {
 111  0
         write(buffer, 0, buffer.length);
 112  0
     }
 113  
 
 114  
 
 115  
     /***
 116  
      * Writes a number of bytes from a byte array to the stream starting from
 117  
      * a given offset.
 118  
      * <p>
 119  
      * @param buffer  The byte array to write.
 120  
      * @param offset  The offset into the array at which to start copying data.
 121  
      * @param length  The number of bytes to write.
 122  
      * @exception IOException If an error occurs while writing to the underlying
 123  
      *            stream.
 124  
      ***/
 125  
     public void write(byte buffer[], int offset, class="keyword">int length) throws IOException
 126  
     {
 127  0
         synchronized (__client)
 128  
         {
 129  0
             while (length-- > 0)
 130  0
                 write(buffer[offset++]);
 131  0
         }
 132  0
     }
 133  
 
 134  
     /*** Flushes the stream. ***/
 135  
     public void flush() throws IOException
 136  
     {
 137  34
         __client._flushOutputStream();
 138  34
     }
 139  
 
 140  
     /*** Closes the stream. ***/
 141  
     public void close() throws IOException
 142  
     {
 143  32
         __client._closeOutputStream();
 144  32
     }
 145  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.