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 / ByteSwapInputStream.java < prev    next >
Encoding:
Java Source  |  1997-07-03  |  1.2 KB  |  58 lines

  1. /*
  2.  * @(#)ByteSwapInputStream.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 InputStream.
  15.  * The read method switches byte order.
  16.  * It is used for dealing with littleendian format.
  17.  *
  18.  * @version 1.0, 6/5/97
  19.  */
  20. class ByteSwapInputStream extends InputStream
  21. {
  22.     public ByteSwapInputStream( InputStream in )
  23.     {
  24.         this.in = in;
  25.         this.byte1 = -2;
  26.     }
  27.  
  28.     public int read() throws IOException
  29.     {   
  30.         if( byte1 == -2 )
  31.         {
  32.             byte1 = in.read();                
  33.  
  34.             if ( byte1 == -1 ) {            
  35.                 return -1;                
  36.             }
  37.  
  38.             return in.read();                
  39.         }                  
  40.         else
  41.         {        
  42.             int temp = byte1;
  43.             byte1 = -2;
  44.             return temp;
  45.         }
  46.     }        
  47.  
  48.     /**
  49.      * The input stream for reading characters
  50.      */
  51.     private InputStream in;
  52.  
  53.     /**
  54.      * byte used for byteswapping purposes...
  55.      */
  56.     private int byte1;
  57. }
  58.