/Users/lyon/j4p/src/ip/gif/gifAnimation/Put.java

1    //****************************************************************************** 
2    // Put.java 
3    //****************************************************************************** 
4    package ip.gif.gifAnimation; 
5     
6    import java.io.IOException; 
7    import java.io.OutputStream; 
8     
9    //============================================================================== 
10    
11   /** Just a couple of trivial output routines used by other classes in the 
12    *  package.  Normally this kind of stuff would be in a separate IO package, but 
13    *  I wanted the present package to be self-contained for ease of distribution 
14    *  and use by others. 
15    */ 
16   final class Put { 
17    
18       //---------------------------------------------------------------------------- 
19       /** Write just the low bytes of a String.  (This sucks, but the concept of an 
20        *  encoding seems inapplicable to a binary file ID string.  I would think 
21        *  flexibility is just what we don't want - but then again, maybe I'm slow.) 
22        */ 
23       static void ascii(String s, OutputStream os) throws IOException { 
24           byte[] bytes = new byte[s.length()]; 
25           for (int i = 0; i < bytes.length; ++i) 
26               bytes[i] = (byte) s.charAt(i);  // discard the high byte 
27           os.write(bytes); 
28       } 
29    
30       //---------------------------------------------------------------------------- 
31       /** Write a 16-bit integer in little endian byte order. 
32        */ 
33       static void leShort(int i16, OutputStream os) throws IOException { 
34           os.write(i16 & 0xff); 
35           os.write(i16 >> 8 & 0xff); 
36       } 
37   }