KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > jcd > lib > UDataInputStream


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: UDataInputStream.java,v 1.1.1.1.2.1 2004/07/10 03:34:53 vlad_r Exp $
8  */

9 package com.vladium.jcd.lib;
10
11 import java.io.DataInputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.InputStream JavaDoc;
14
15 // ----------------------------------------------------------------------------
16
/**
17  * A trivial extension to java.io.DataInputStream to provide methods for
18  * reading unsigned 16- and 32-bit integers with simple mnemonics. It uses
19  * correspondingly wider native types to preserve the full range of the unsigned
20  * types.
21  *
22  * @author (C) 2001, Vlad Roubtsov
23  */

24 public
25 final class UDataInputStream extends DataInputStream JavaDoc
26 {
27     // public: ................................................................
28

29     
30     public UDataInputStream (final InputStream JavaDoc _in)
31     {
32         super (_in);
33     }
34
35     
36     public final int readU2 () throws IOException JavaDoc
37     {
38         final short value = readShort ();
39         
40         return ((int) value) & 0xFFFF; // widening cast sign-extends
41
}
42     
43     
44     public final long readU4 () throws IOException JavaDoc
45     {
46         final int value = readInt ();
47         
48         return ((long) value) & 0xFFFFFFFFL; // widening cast sign-extends
49
}
50     
51     // protected: .............................................................
52

53     // package: ...............................................................
54

55     // private: ...............................................................
56

57 } // end of class
58
// ----------------------------------------------------------------------------
59
Popular Tags