< prev index next >

src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/packaging/mime/util/UUDecoderStream.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  61     public UUDecoderStream(InputStream in) {
  62         super(in);
  63         lin = new LineInputStream(in);
  64         buffer = new byte[45]; // max decoded chars in a line = 45
  65     }
  66 
  67     /**
  68      * Read the next decoded byte from this input stream. The byte
  69      * is returned as an <code>int</code> in the range <code>0</code>
  70      * to <code>255</code>. If no byte is available because the end of
  71      * the stream has been reached, the value <code>-1</code> is returned.
  72      * This method blocks until input data is available, the end of the
  73      * stream is detected, or an exception is thrown.
  74      *
  75      * @return     next byte of data, or <code>-1</code> if the end of
  76      *             stream is reached.
  77      * @exception  IOException  if an I/O error occurs.
  78      * @see        java.io.FilterInputStream#in
  79      */
  80 

  81     public int read() throws IOException {
  82         if (index >= bufsize) {
  83             readPrefix();
  84             if (!decode())
  85                 return -1;
  86             index = 0; // reset index into buffer
  87         }
  88         return buffer[index++] & 0xff; // return lower byte
  89     }
  90 

  91     public int read(byte[] buf, int off, int len) throws IOException {
  92         int i, c;
  93         for (i = 0; i < len; i++) {
  94             if ((c = read()) == -1) {
  95                 if (i == 0) // At end of stream, so we should
  96                     i = -1; // return -1, NOT 0.
  97                 break;
  98             }
  99             buf[off+i] = (byte)c;
 100         }
 101         return i;
 102     }
 103 

 104     public boolean markSupported() {
 105         return false;
 106     }
 107 

 108     public int available() throws IOException {
 109          // This is only an estimate, since in.available()
 110          // might include CRLFs too ..
 111          return ((in.available() * 3)/4 + (bufsize-index));
 112     }
 113 
 114     /**
 115      * Get the "name" field from the prefix. This is meant to
 116      * be the pathname of the decoded file
 117      *
 118      * @return     name of decoded file
 119      * @exception  IOException  if an I/O error occurs.
 120      */
 121     public String getName() throws IOException {
 122         readPrefix();
 123         return name;
 124     }
 125 
 126     /**
 127      * Get the "mode" field from the prefix. This is the permission


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  61     public UUDecoderStream(InputStream in) {
  62         super(in);
  63         lin = new LineInputStream(in);
  64         buffer = new byte[45]; // max decoded chars in a line = 45
  65     }
  66 
  67     /**
  68      * Read the next decoded byte from this input stream. The byte
  69      * is returned as an <code>int</code> in the range <code>0</code>
  70      * to <code>255</code>. If no byte is available because the end of
  71      * the stream has been reached, the value <code>-1</code> is returned.
  72      * This method blocks until input data is available, the end of the
  73      * stream is detected, or an exception is thrown.
  74      *
  75      * @return     next byte of data, or <code>-1</code> if the end of
  76      *             stream is reached.
  77      * @exception  IOException  if an I/O error occurs.
  78      * @see        java.io.FilterInputStream#in
  79      */
  80 
  81     @Override
  82     public int read() throws IOException {
  83         if (index >= bufsize) {
  84             readPrefix();
  85             if (!decode())
  86                 return -1;
  87             index = 0; // reset index into buffer
  88         }
  89         return buffer[index++] & 0xff; // return lower byte
  90     }
  91 
  92     @Override
  93     public int read(byte[] buf, int off, int len) throws IOException {
  94         int i, c;
  95         for (i = 0; i < len; i++) {
  96             if ((c = read()) == -1) {
  97                 if (i == 0) // At end of stream, so we should
  98                     i = -1; // return -1, NOT 0.
  99                 break;
 100             }
 101             buf[off+i] = (byte)c;
 102         }
 103         return i;
 104     }
 105 
 106     @Override
 107     public boolean markSupported() {
 108         return false;
 109     }
 110 
 111     @Override
 112     public int available() throws IOException {
 113          // This is only an estimate, since in.available()
 114          // might include CRLFs too ..
 115          return ((in.available() * 3)/4 + (bufsize-index));
 116     }
 117 
 118     /**
 119      * Get the "name" field from the prefix. This is meant to
 120      * be the pathname of the decoded file
 121      *
 122      * @return     name of decoded file
 123      * @exception  IOException  if an I/O error occurs.
 124      */
 125     public String getName() throws IOException {
 126         readPrefix();
 127         return name;
 128     }
 129 
 130     /**
 131      * Get the "mode" field from the prefix. This is the permission


< prev index next >