home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML in Action / Dynamicke-HTML-v-akci-covermount.bin / XML / PARSER / XMLINST.EXE / classes / com / ms / xml / util / ByteSwapOutputStream.java < prev    next >
Encoding:
Java Source  |  1997-07-03  |  1.1 KB  |  61 lines

  1. /*
  2.  * @(#)ByteSwapOutputStream.java 1.0 6/5/97
  3.  * 
  4.  * Copyright (c) 1997 Microsoft, Corp. All Rights Reserved.
  5.  * 
  6.  */
  7.  
  8. package com.ms.xml.util;
  9.  
  10. import java.io.*;
  11.  
  12. /**
  13.  * 
  14.  * This is a class that extends OutputStream.
  15.  * It swap bytes order and is intended to create Littleendian format.
  16.  *
  17.  * @version 1.0, 6/9/97
  18.  */
  19. class ByteSwapOutputStream extends OutputStream
  20. {
  21.     public ByteSwapOutputStream( OutputStream out )
  22.     {
  23.         this.out = out;
  24.         this.byte1 = -2;
  25.  
  26.     }
  27.  
  28.     public void write( int c ) throws IOException
  29.     {
  30.         if( byte1 == -2 )
  31.         {
  32.             byte1 = c;
  33.         }
  34.         else
  35.         {
  36.             out.write( c );
  37.             out.write( byte1 );
  38.             byte1 = -2;
  39.         }
  40.     }
  41.  
  42.     public void close() throws IOException
  43.     {
  44.         if( byte1 != -2 )
  45.         {
  46.             out.write( 0x00 );
  47.             out.write( byte1 );
  48.         }
  49.     }
  50.  
  51.     /**
  52.      * The input stream for reading characters
  53.      */
  54.     private OutputStream out;
  55.  
  56.     /**
  57.      * byte used for buffering up writes and swapping order.
  58.      */
  59.     private int byte1;
  60. }
  61.