Show
Ignore:
Timestamp:
09/13/10 19:24:53 (21 months ago)
Author:
mgriffel
Message:

Added new method IoUtil#skip(). Wraps strange InputStream#skip?() that violates the POLA.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/java/org/jcoderz/commons/util/IoUtil.java

    r1500 r1638  
    3434 
    3535import java.io.ByteArrayOutputStream; 
     36import java.io.EOFException; 
    3637import java.io.File; 
    3738import java.io.FileInputStream; 
     
    418419      } 
    419420   } 
     421    
     422   /** 
     423    * Ensures that the given number of bytes are skipped from the given  
     424    * input stream. 
     425    * @param in the input stream. 
     426    * @param bytes the number of bytes to skip. 
     427    * @throws IOException if the stream does not support seek, 
     428    *              or if some other I/O error occurs. 
     429    * @see InputStream#skip              
     430    */ 
     431    public static void skip (InputStream in, int bytes) 
     432        throws IOException 
     433    { 
     434        long remaining = bytes; 
     435        while (remaining != 0) 
     436        { 
     437            final long skipped = in.skip(remaining); 
     438            if (skipped == 0) 
     439            { 
     440                throw new EOFException(); 
     441            } 
     442            remaining -= skipped; 
     443        } 
     444    } 
    420445 
    421446