Home | History | Annotate | Download | only in io
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2014 Eric Lafortune (eric (at) graphics.cornell.edu)
      6  *
      7  * This program is free software; you can redistribute it and/or modify it
      8  * under the terms of the GNU General Public License as published by the Free
      9  * Software Foundation; either version 2 of the License, or (at your option)
     10  * any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful, but WITHOUT
     13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     15  * more details.
     16  *
     17  * You should have received a copy of the GNU General Public License along
     18  * with this program; if not, write to the Free Software Foundation, Inc.,
     19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  */
     21 package proguard.classfile.io;
     22 
     23 import java.io.*;
     24 
     25 /**
     26  * This class delegates its method calls to the corresponding DataInput methods,
     27  * converting its IOExceptions to RuntimeExceptions.
     28  *
     29  * @author Eric Lafortune
     30  */
     31 final class RuntimeDataInput
     32 {
     33     private final DataInput dataInput;
     34 
     35 
     36     public RuntimeDataInput(DataInput dataInput)
     37     {
     38         this.dataInput = dataInput;
     39     }
     40 
     41 
     42     // Methods delegating to DataInput.
     43 
     44     public boolean readBoolean()
     45     {
     46         try
     47         {
     48             return dataInput.readBoolean();
     49         }
     50         catch (IOException ex)
     51         {
     52             throw new RuntimeException(ex.getMessage());
     53         }
     54     }
     55 
     56     public byte readByte()
     57     {
     58         try
     59         {
     60             return dataInput.readByte();
     61         }
     62         catch (IOException ex)
     63         {
     64             throw new RuntimeException(ex.getMessage());
     65         }
     66     }
     67 
     68     public char readChar()
     69     {
     70         try
     71         {
     72             return dataInput.readChar();
     73         }
     74         catch (IOException ex)
     75         {
     76             throw new RuntimeException(ex.getMessage());
     77         }
     78     }
     79 
     80     public double readDouble()
     81     {
     82         try
     83         {
     84             return dataInput.readDouble();
     85         }
     86         catch (IOException ex)
     87         {
     88             throw new RuntimeException(ex.getMessage());
     89         }
     90     }
     91 
     92     public float readFloat()
     93     {
     94         try
     95         {
     96             return dataInput.readFloat();
     97         }
     98         catch (IOException ex)
     99         {
    100             throw new RuntimeException(ex.getMessage());
    101         }
    102     }
    103 
    104     public void readFully(byte[] b)
    105     {
    106         try
    107         {
    108             dataInput.readFully(b);
    109         }
    110         catch (IOException ex)
    111         {
    112             throw new RuntimeException(ex.getMessage());
    113         }
    114     }
    115 
    116     public void readFully(byte[] b, int off, int len)
    117     {
    118         try
    119         {
    120             dataInput.readFully(b, off, len);
    121         }
    122         catch (IOException ex)
    123         {
    124             throw new RuntimeException(ex.getMessage());
    125         }
    126     }
    127 
    128     public int readInt()
    129     {
    130         try
    131         {
    132             return dataInput.readInt();
    133         }
    134         catch (IOException ex)
    135         {
    136             throw new RuntimeException(ex.getMessage());
    137         }
    138     }
    139 
    140     public String readLine()
    141     {
    142         try
    143         {
    144             return dataInput.readLine();
    145         }
    146         catch (IOException ex)
    147         {
    148             throw new RuntimeException(ex.getMessage());
    149         }
    150     }
    151 
    152     public long readLong()
    153     {
    154         try
    155         {
    156             return dataInput.readLong();
    157         }
    158         catch (IOException ex)
    159         {
    160             throw new RuntimeException(ex.getMessage());
    161         }
    162     }
    163 
    164     public short readShort()
    165     {
    166         try
    167         {
    168             return dataInput.readShort();
    169         }
    170         catch (IOException ex)
    171         {
    172             throw new RuntimeException(ex.getMessage());
    173         }
    174     }
    175 
    176     public int readUnsignedByte()
    177     {
    178         try
    179         {
    180             return dataInput.readUnsignedByte();
    181         }
    182         catch (IOException ex)
    183         {
    184             throw new RuntimeException(ex.getMessage());
    185         }
    186     }
    187 
    188     public int readUnsignedShort()
    189     {
    190         try
    191         {
    192             return dataInput.readUnsignedShort();
    193         }
    194         catch (IOException ex)
    195         {
    196             throw new RuntimeException(ex.getMessage());
    197         }
    198     }
    199 
    200     public String readUTF()
    201     {
    202         try
    203         {
    204             return dataInput.readUTF();
    205         }
    206         catch (IOException ex)
    207         {
    208             throw new RuntimeException(ex.getMessage());
    209         }
    210     }
    211 
    212     public int skipBytes(int n)
    213     {
    214         try
    215         {
    216             return dataInput.skipBytes(n);
    217         }
    218         catch (IOException ex)
    219         {
    220             throw new RuntimeException(ex.getMessage());
    221         }
    222     }
    223 }
    224