KickJava   Java API By Example, From Geeks To Geeks.

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


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: UDataOutputStream.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.DataOutputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.OutputStream JavaDoc;
14
15 // ----------------------------------------------------------------------------
16
/**
17  * A trivial extension to java.io.DataInputStream to provide methods for
18  * writing 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 UDataOutputStream extends DataOutputStream JavaDoc
26 {
27     // public: ................................................................
28

29     
30     public UDataOutputStream (final OutputStream JavaDoc _out)
31     {
32         super (_out);
33     }
34     
35     
36     public final void writeU2 (final int uint) throws IOException JavaDoc
37     {
38         writeShort ((short) uint); // this narrowing cast is Ok
39
}
40     
41     
42     public final void writeU4 (final long ulong) throws IOException JavaDoc
43     {
44         writeInt ((int) ulong); // this narrowing cast is Ok
45
}
46     
47     // protected: .............................................................
48

49     // package: ...............................................................
50

51     // private: ...............................................................
52

53 } // end of class
54
// ----------------------------------------------------------------------------
55
Popular Tags