Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 69534200B5B for ; Fri, 1 Jul 2016 07:49:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 67CBD160A74; Fri, 1 Jul 2016 05:49:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 432D7160A75 for ; Fri, 1 Jul 2016 07:49:08 +0200 (CEST) Received: (qmail 10318 invoked by uid 500); 1 Jul 2016 05:49:07 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 10309 invoked by uid 99); 1 Jul 2016 05:49:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2016 05:49:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B2DEF187827 for ; Fri, 1 Jul 2016 05:49:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.374 X-Spam-Level: X-Spam-Status: No, score=0.374 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id rs6sA51YK99K for ; Fri, 1 Jul 2016 05:48:46 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id AA1415FD43 for ; Fri, 1 Jul 2016 05:48:45 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A7FFBE7370 for ; Fri, 1 Jul 2016 05:48:42 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 97B033A27DA for ; Fri, 1 Jul 2016 05:48:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r991782 [35/46] - in /websites/production/commons/content/proper/commons-fileupload: ./ apidocs/ apidocs/org/apache/commons/fileupload/ apidocs/org/apache/commons/fileupload/class-use/ apidocs/org/apache/commons/fileupload/disk/ apidocs/org... Date: Fri, 01 Jul 2016 05:48:38 -0000 To: notifications@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160701054842.97B033A27DA@svn01-us-west.apache.org> archived-at: Fri, 01 Jul 2016 05:49:10 -0000 Added: websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.LimitedInputStream.html ============================================================================== --- websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.LimitedInputStream.html (added) +++ websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.LimitedInputStream.html Fri Jul 1 05:48:35 2016 @@ -0,0 +1,338 @@ + + + + +Coverage Report + + + + +
Coverage Report - org.apache.commons.fileupload.util.LimitedInputStream
+
 
+ + + + +
Classes in this File Line Coverage Branch Coverage Complexity
LimitedInputStream
75%
15/20
66%
4/6
1,429
+
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.fileupload.util;
 18  
 
 19  
 import java.io.FilterInputStream;
 20  
 import java.io.IOException;
 21  
 import java.io.InputStream;
 22  
 
 23  
 /**
 24  
  * An input stream, which limits its data size. This stream is
 25  
  * used, if the content length is unknown.
 26  
  *
 27  
  * @version $Id: LimitedInputStream.java 1747113 2016-06-07 02:19:02Z ggregory $
 28  
  */
 29  
 public abstract class LimitedInputStream extends FilterInputStream implements Closeable {
 30  
 
 31  
     /**
 32  
      * The maximum size of an item, in bytes.
 33  
      */
 34  
     private final long sizeMax;
 35  
 
 36  
     /**
 37  
      * The current number of bytes.
 38  
      */
 39  
     private long count;
 40  
 
 41  
     /**
 42  
      * Whether this stream is already closed.
 43  
      */
 44  
     private boolean closed;
 45  
 
 46  
     /**
 47  
      * Creates a new instance.
 48  
      *
 49  
      * @param inputStream The input stream, which shall be limited.
 50  
      * @param pSizeMax The limit; no more than this number of bytes
 51  
      *   shall be returned by the source stream.
 52  
      */
 53  
     public LimitedInputStream(InputStream inputStream, long pSizeMax) {
 54  5
         super(inputStream);
 55  5
         sizeMax = pSizeMax;
 56  5
     }
 57  
 
 58  
     /**
 59  
      * Called to indicate, that the input streams limit has
 60  
      * been exceeded.
 61  
      *
 62  
      * @param pSizeMax The input streams limit, in bytes.
 63  
      * @param pCount The actual number of bytes.
 64  
      * @throws IOException The called method is expected
 65  
      *   to raise an IOException.
 66  
      */
 67  
     protected abstract void raiseError(long pSizeMax, long pCount)
 68  
             throws IOException;
 69  
 
 70  
     /**
 71  
      * Called to check, whether the input streams
 72  
      * limit is reached.
 73  
      *
 74  
      * @throws IOException The given limit is exceeded.
 75  
      */
 76  
     private void checkLimit() throws IOException {
 77  36
         if (count > sizeMax) {
 78  4
             raiseError(sizeMax, count);
 79  
         }
 80  32
     }
 81  
 
 82  
     /**
 83  
      * Reads the next byte of data from this input stream. The value
 84  
      * byte is returned as an <code>int</code> in the range
 85  
      * <code>0</code> to <code>255</code>. If no byte is available
 86  
      * because the end of the stream has been reached, the value
 87  
      * <code>-1</code> is returned. This method blocks until input data
 88  
      * is available, the end of the stream is detected, or an exception
 89  
      * is thrown.
 90  
      * <p>
 91  
      * This method
 92  
      * simply performs <code>in.read()</code> and returns the result.
 93  
      *
 94  
      * @return     the next byte of data, or <code>-1</code> if the end of the
 95  
      *             stream is reached.
 96  
      * @throws  IOException  if an I/O error occurs.
 97  
      * @see        java.io.FilterInputStream#in
 98  
      */
 99  
     @Override
 100  
     public int read() throws IOException {
 101  0
         int res = super.read();
 102  0
         if (res != -1) {
 103  0
             count++;
 104  0
             checkLimit();
 105  
         }
 106  0
         return res;
 107  
     }
 108  
 
 109  
     /**
 110  
      * Reads up to <code>len</code> bytes of data from this input stream
 111  
      * into an array of bytes. If <code>len</code> is not zero, the method
 112  
      * blocks until some input is available; otherwise, no
 113  
      * bytes are read and <code>0</code> is returned.
 114  
      * <p>
 115  
      * This method simply performs <code>in.read(b, off, len)</code>
 116  
      * and returns the result.
 117  
      *
 118  
      * @param      b     the buffer into which the data is read.
 119  
      * @param      off   The start offset in the destination array
 120  
      *                   <code>b</code>.
 121  
      * @param      len   the maximum number of bytes read.
 122  
      * @return     the total number of bytes read into the buffer, or
 123  
      *             <code>-1</code> if there is no more data because the end of
 124  
      *             the stream has been reached.
 125  
      * @throws  NullPointerException If <code>b</code> is <code>null</code>.
 126  
      * @throws  IndexOutOfBoundsException If <code>off</code> is negative,
 127  
      * <code>len</code> is negative, or <code>len</code> is greater than
 128  
      * <code>b.length - off</code>
 129  
      * @throws  IOException  if an I/O error occurs.
 130  
      * @see        java.io.FilterInputStream#in
 131  
      */
 132  
     @Override
 133  
     public int read(byte[] b, int off, int len) throws IOException {
 134  38
         int res = super.read(b, off, len);
 135  38
         if (res > 0) {
 136  36
             count += res;
 137  36
             checkLimit();
 138  
         }
 139  34
         return res;
 140  
     }
 141  
 
 142  
     /**
 143  
      * Returns, whether this stream is already closed.
 144  
      *
 145  
      * @return True, if the stream is closed, otherwise false.
 146  
      * @throws IOException An I/O error occurred.
 147  
      */
 148  
     public boolean isClosed() throws IOException {
 149  4
         return closed;
 150  
     }
 151  
 
 152  
     /**
 153  
      * Closes this input stream and releases any system resources
 154  
      * associated with the stream.
 155  
      * This
 156  
      * method simply performs <code>in.close()</code>.
 157  
      *
 158  
      * @throws  IOException  if an I/O error occurs.
 159  
      * @see        java.io.FilterInputStream#in
 160  
      */
 161  
     @Override
 162  
     public void close() throws IOException {
 163  6
         closed = true;
 164  6
         super.close();
 165  6
     }
 166  
 
 167  
 }
+ + + + \ No newline at end of file Propchange: websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.LimitedInputStream.html ------------------------------------------------------------------------------ svn:eol-style = native Added: websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.Streams.html ============================================================================== --- websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.Streams.html (added) +++ websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.Streams.html Fri Jul 1 05:48:35 2016 @@ -0,0 +1,373 @@ + + + + +Coverage Report + + + + +
Coverage Report - org.apache.commons.fileupload.util.Streams
+
 
+ + + + +
Classes in this File Line Coverage Branch Coverage Complexity
Streams
78%
32/41
90%
18/20
3,167
+
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.fileupload.util;
 18  
 
 19  
 import java.io.ByteArrayOutputStream;
 20  
 import java.io.IOException;
 21  
 import java.io.InputStream;
 22  
 import java.io.OutputStream;
 23  
 
 24  
 import org.apache.commons.fileupload.InvalidFileNameException;
 25  
 import org.apache.commons.io.IOUtils;
 26  
 
 27  
 /**
 28  
  * Utility class for working with streams.
 29  
  *
 30  
  * @version $Id: Streams.java 1565332 2014-02-06 16:42:19Z ggregory $
 31  
  */
 32  
 public final class Streams {
 33  
 
 34  
     /**
 35  
      * Private constructor, to prevent instantiation.
 36  
      * This class has only static methods.
 37  
      */
 38  0
     private Streams() {
 39  
         // Does nothing
 40  0
     }
 41  
 
 42  
     /**
 43  
      * Default buffer size for use in
 44  
      * {@link #copy(InputStream, OutputStream, boolean)}.
 45  
      */
 46  
     private static final int DEFAULT_BUFFER_SIZE = 8192;
 47  
 
 48  
     /**
 49  
      * Copies the contents of the given {@link InputStream}
 50  
      * to the given {@link OutputStream}. Shortcut for
 51  
      * <pre>
 52  
      *   copy(pInputStream, pOutputStream, new byte[8192]);
 53  
      * </pre>
 54  
      *
 55  
      * @param inputStream The input stream, which is being read.
 56  
      * It is guaranteed, that {@link InputStream#close()} is called
 57  
      * on the stream.
 58  
      * @param outputStream The output stream, to which data should
 59  
      * be written. May be null, in which case the input streams
 60  
      * contents are simply discarded.
 61  
      * @param closeOutputStream True guarantees, that {@link OutputStream#close()}
 62  
      * is called on the stream. False indicates, that only
 63  
      * {@link OutputStream#flush()} should be called finally.
 64  
      *
 65  
      * @return Number of bytes, which have been copied.
 66  
      * @throws IOException An I/O error occurred.
 67  
      */
 68  
     public static long copy(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream)
 69  
             throws IOException {
 70  5324
         return copy(inputStream, outputStream, closeOutputStream, new byte[DEFAULT_BUFFER_SIZE]);
 71  
     }
 72  
 
 73  
     /**
 74  
      * Copies the contents of the given {@link InputStream}
 75  
      * to the given {@link OutputStream}.
 76  
      *
 77  
      * @param inputStream The input stream, which is being read.
 78  
      *   It is guaranteed, that {@link InputStream#close()} is called
 79  
      *   on the stream.
 80  
      * @param outputStream The output stream, to which data should
 81  
      *   be written. May be null, in which case the input streams
 82  
      *   contents are simply discarded.
 83  
      * @param closeOutputStream True guarantees, that {@link OutputStream#close()}
 84  
      *   is called on the stream. False indicates, that only
 85  
      *   {@link OutputStream#flush()} should be called finally.
 86  
      * @param buffer Temporary buffer, which is to be used for
 87  
      *   copying data.
 88  
      * @return Number of bytes, which have been copied.
 89  
      * @throws IOException An I/O error occurred.
 90  
      */
 91  
     public static long copy(InputStream inputStream,
 92  
             OutputStream outputStream, boolean closeOutputStream,
 93  
             byte[] buffer)
 94  
     throws IOException {
 95  5324
         OutputStream out = outputStream;
 96  5324
         InputStream in = inputStream;
 97  
         try {
 98  5324
             long total = 0;
 99  
             for (;;) {
 100  14822
                 int res = in.read(buffer);
 101  14817
                 if (res == -1) {
 102  5319
                     break;
 103  
                 }
 104  9498
                 if (res > 0) {
 105  9498
                     total += res;
 106  9498
                     if (out != null) {
 107  6339
                         out.write(buffer, 0, res);
 108  
                     }
 109  
                 }
 110  9498
             }
 111  5319
             if (out != null) {
 112  2133
                 if (closeOutputStream) {
 113  2133
                     out.close();
 114  
                 } else {
 115  0
                     out.flush();
 116  
                 }
 117  2133
                 out = null;
 118  
             }
 119  5319
             in.close();
 120  5319
             in = null;
 121  5319
             return total;
 122  
         } finally {
 123  5324
             IOUtils.closeQuietly(in);
 124  5324
             if (closeOutputStream) {
 125  2137
                 IOUtils.closeQuietly(out);
 126  
             }
 127  
         }
 128  
     }
 129  
 
 130  
     /**
 131  
      * This convenience method allows to read a
 132  
      * {@link org.apache.commons.fileupload.FileItemStream}'s
 133  
      * content into a string. The platform's default character encoding
 134  
      * is used for converting bytes into characters.
 135  
      *
 136  
      * @param inputStream The input stream to read.
 137  
      * @see #asString(InputStream, String)
 138  
      * @return The streams contents, as a string.
 139  
      * @throws IOException An I/O error occurred.
 140  
      */
 141  
     public static String asString(InputStream inputStream) throws IOException {
 142  0
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 143  0
         copy(inputStream, baos, true);
 144  0
         return baos.toString();
 145  
     }
 146  
 
 147  
     /**
 148  
      * This convenience method allows to read a
 149  
      * {@link org.apache.commons.fileupload.FileItemStream}'s
 150  
      * content into a string, using the given character encoding.
 151  
      *
 152  
      * @param inputStream The input stream to read.
 153  
      * @param encoding The character encoding, typically "UTF-8".
 154  
      * @see #asString(InputStream)
 155  
      * @return The streams contents, as a string.
 156  
      * @throws IOException An I/O error occurred.
 157  
      */
 158  
     public static String asString(InputStream inputStream, String encoding) throws IOException {
 159  0
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 160  0
         copy(inputStream, baos, true);
 161  0
         return baos.toString(encoding);
 162  
     }
 163  
 
 164  
     /**
 165  
      * Checks, whether the given file name is valid in the sense,
 166  
      * that it doesn't contain any NUL characters. If the file name
 167  
      * is valid, it will be returned without any modifications. Otherwise,
 168  
      * an {@link InvalidFileNameException} is raised.
 169  
      *
 170  
      * @param fileName The file name to check
 171  
      * @return Unmodified file name, if valid.
 172  
      * @throws InvalidFileNameException The file name was found to be invalid.
 173  
      */
 174  
     public static String checkFileName(String fileName) {
 175  13
         if (fileName != null  &&  fileName.indexOf('\u0000') != -1) {
 176  
             // pFileName.replace("\u0000", "\\0")
 177  2
             final StringBuilder sb = new StringBuilder();
 178  26
             for (int i = 0;  i < fileName.length();  i++) {
 179  24
                 char c = fileName.charAt(i);
 180  24
                 switch (c) {
 181  
                     case 0:
 182  2
                         sb.append("\\0");
 183  2
                         break;
 184  
                     default:
 185  22
                         sb.append(c);
 186  
                         break;
 187  
                 }
 188  
             }
 189  2
             throw new InvalidFileNameException(fileName,
 190  
                     "Invalid file name: " + sb);
 191  
         }
 192  11
         return fileName;
 193  
     }
 194  
 
 195  
 }
+ + + + \ No newline at end of file Propchange: websites/production/commons/content/proper/commons-fileupload/cobertura/org.apache.commons.fileupload.util.Streams.html ------------------------------------------------------------------------------ svn:eol-style = native