1 /*
2  *  (C) 2001 by Argonne National Laboratory
3  *      See COPYRIGHT in top-level directory.
4  */
5 
6 /*
7  *  @author  Anthony Chan
8  */
9 package base.io;
10 
11 import java.io.InputStream;
12 import java.io.DataInputStream;
13 
14 public class MixedDataInputStream extends DataInputStream
15                                   implements MixedDataInput
16 {
MixedDataInputStream( InputStream ins )17     public MixedDataInputStream( InputStream ins )
18     {
19         super( ins );
20     }
21 
readString()22     public String readString()
23     throws java.io.IOException
24     {
25         short strlen = super.readShort();
26         if ( strlen > 0 ) {
27             byte[] bytebuf = new byte[ strlen ];
28             super.readFully( bytebuf );
29             // return ( new String( bytebuf ) ).trim();
30             return ( new String( bytebuf ) );
31         }
32         else
33             return "";
34     }
35 
readStringWithLimit( short max_strlen )36     public String readStringWithLimit( short max_strlen )
37     throws java.io.IOException
38     {
39         short strlen = super.readShort();
40         if ( strlen > 0 ) {
41             if ( strlen > max_strlen )
42                 strlen = max_strlen;
43             byte[] bytebuf = new byte[ strlen ];
44             super.readFully( bytebuf );
45             // return ( new String( bytebuf ) ).trim();
46             return ( new String( bytebuf ) );
47         }
48         else
49             return "";
50     }
51 }
52