/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t C S   i s   J a v a   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 u s i n g   S y s t e m ; 
 
 u s i n g   S y s t e m . I O ; 
 
 u s i n g   S y s t e m . D i a g n o s t i c s ; 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e 
 
 { 
 
         / * * 
 
           *   { @ l i n k   I n p u t S t r e a m } K000QY0_00n0
 
           *   @ a u t h o r   n y a t l a 
 
           * 
 
           * / 
 
         p u b l i c   c l a s s   B y t e B u f f e r e d I n p u t S t r e a m 
 
         { 
 
 	         p u b l i c   c o n s t   i n t   E N D I A N _ L I T T L E = 1 ; 
 
                 p u b l i c   c o n s t   i n t   E N D I A N _ B I G   =   2 ; 
 
                 p r i v a t e   b y t e [ ]   _ b u f ; 
 
                 p r i v a t e   B i n a r y R e a d e r   _ s t r e a m ; 
 
                 p r i v a t e   b o o l   _ i s _ b y t e _ s w a p ; 
 
                 p r i v a t e   i n t   _ r e a d _ l e n ; 
 
                 p u b l i c   B y t e B u f f e r e d I n p u t S t r e a m ( S t r e a m R e a d e r   i _ s t r e a m ,   i n t   i _ b u f _ s i z e ) 
 
                 { 
 
                         t h i s . _ b u f   =   n e w   b y t e [ i _ b u f _ s i z e ] ; 
 
                         t h i s . _ r e a d _ l e n   =   0 ; 
 
                         t h i s . _ s t r e a m   =   n e w   B i n a r y R e a d e r ( i _ s t r e a m . B a s e S t r e a m ) ; 
 
                 } 
 
                 / * * 
 
                   *   00000000Bfn0000000. { @ l i n k   # E N D I A N _ B I G } K0{ @ l i n k   # E N D I A N _ L I T T L E } 0-[W0f0O0`0U0D00
 
                   *   @ p a r a m   i _ o r d e r 
 
                   * / 
 
                 p u b l i c   v o i d   o r d e r ( i n t   i _ o r d e r ) 
 
                 { 
 
                         s w i t c h   ( i _ o r d e r ) 
 
                         { 
 
                                 c a s e   E N D I A N _ L I T T L E : 
 
                                         t h i s . _ i s _ b y t e _ s w a p   =   B i t C o n v e r t e r . I s L i t t l e E n d i a n ? f a l s e : t r u e ; 
 
                                         b r e a k ; 
 
                                 c a s e   E N D I A N _ B I G : 
 
                                         t h i s . _ i s _ b y t e _ s w a p   =   B i t C o n v e r t e r . I s L i t t l e E n d i a n   ?   t r u e   :   f a l s e ; 
 
                                         b r e a k ; 
 
                                 d e f a u l t : 
 
                                         t h r o w   n e w   N y A R E x c e p t i o n ( ) ; 
 
                         } 
 
                 } 
 
                 / * * 
 
                   *   S t r e a m K000000x0i _ s i z e `0Q00QY00
 
                   *   @ p a r a m   i _ s i z e 
 
                   *   @ t h r o w s   N y A R E x c e p t i o n   
 
                   * / 
 
                 p u b l i c   i n t   r e a d T o B u f f e r ( i n t   i _ s i z e ) 
 
                 { 
 
                         D e b u g . A s s e r t ( t h i s . _ r e a d _ l e n   <   t h i s . _ b u f . L e n g t h ) ; 
 
                         i n t   l e n ; 
 
                         t r y 
 
                         { 
 
                                 l e n = t h i s . _ s t r e a m . R e a d ( t h i s . _ b u f ,   0 ,   i _ s i z e ) ; 
 
                         } 
 
                         c a t c h   ( I O E x c e p t i o n   e ) 
 
                         { 
 
                                 t h r o w   n e w   N y A R E x c e p t i o n ( e ) ; 
 
                         } 
 
                         / / 0000n00QW0MOn00000
 
                         t h i s . _ r e a d _ l e n   =   0 ; 
 
                         r e t u r n   l e n ; 
 
                 } 
 
                 p u b l i c   i n t   r e a d B y t e s ( b y t e [ ]   i _ b u f ,   i n t   i _ s i z e ) 
 
                 { 
 
                         t r y 
 
                         { 
 
                                 r e t u r n   t h i s . _ s t r e a m . R e a d ( i _ b u f ,   0 ,   i _ s i z e ) ; 
 
                         } 
 
                         c a t c h   ( I O E x c e p t i o n   e ) 
 
                         { 
 
                                 t h r o w   n e w   N y A R E x c e p t i o n ( e ) ; 
 
                         } 
 
                 } 
 
                 p u b l i c   i n t   g e t I n t ( ) 
 
                 { 
 
                         D e b u g . A s s e r t ( t h i s . _ r e a d _ l e n   <   t h i s . _ b u f . L e n g t h ) ; 
 
                         i n t   r e t   =   B i t C o n v e r t e r . T o I n t 3 2 ( t h i s . _ b u f ,   t h i s . _ r e a d _ l e n ) ; 
 
                         t h i s . _ r e a d _ l e n   + =   4 ; 
 
                         i f   ( ! t h i s . _ i s _ b y t e _ s w a p ) 
 
                         { 
 
                                 r e t u r n   r e t ; 
 
                         } 
 
                         / / b i g   e n d i a n 
 
                         b y t e [ ]   b a   =   B i t C o n v e r t e r . G e t B y t e s ( r e t ) ; 
 
                         A r r a y . R e v e r s e ( b a ) ; 
 
                         r e t u r n   B i t C o n v e r t e r . T o I n t 3 2 ( b a ,   0 ) ; 
 
 
 
                 } 
 
                 p u b l i c   b y t e   g e t B y t e ( ) 
 
                 { 
 
                         D e b u g . A s s e r t ( t h i s . _ r e a d _ l e n   <   t h i s . _ b u f . L e n g t h ) ; 
 
                         b y t e   r e t   =   t h i s . _ b u f [ t h i s . _ r e a d _ l e n ] ; 
 
                         t h i s . _ r e a d _ l e n   + =   1 ; 
 
                         r e t u r n   r e t ; 
 
                 } 
 
                 p u b l i c   f l o a t   g e t F l o a t ( ) 
 
                 { 
 
                         D e b u g . A s s e r t ( t h i s . _ r e a d _ l e n   <   t h i s . _ b u f . L e n g t h ) ; 
 
                         f l o a t   r e t   =   B i t C o n v e r t e r . T o S i n g l e ( t h i s . _ b u f , t h i s . _ r e a d _ l e n ) ; 
 
                         t h i s . _ r e a d _ l e n   + =   4 ; 
 
                         i f   ( ! t h i s . _ i s _ b y t e _ s w a p ) 
 
                         { 
 
                                 r e t u r n   r e t ; 
 
                         } 
 
                         / / b i g   e n d i a n 
 
                         b y t e [ ]   b a   =   B i t C o n v e r t e r . G e t B y t e s ( r e t ) ; 
 
                         A r r a y . R e v e r s e ( b a ) ; 
 
                         r e t u r n   B i t C o n v e r t e r . T o S i n g l e ( b a ,   0 ) ; 
 
                 } 
 
                 p u b l i c   d o u b l e   g e t D o u b l e ( ) 
 
                 { 
 
                         D e b u g . A s s e r t ( t h i s . _ r e a d _ l e n   <   t h i s . _ b u f . L e n g t h ) ; 
 
                         d o u b l e   r e t   =   B i t C o n v e r t e r . T o D o u b l e ( t h i s . _ b u f ,   t h i s . _ r e a d _ l e n ) ; 
 
                         t h i s . _ r e a d _ l e n   + =   8 ; 
 
                         i f   ( ! t h i s . _ i s _ b y t e _ s w a p ) 
 
                         { 
 
                                 r e t u r n   r e t ; 
 
                         } 
 
                         / / b i g   e n d i a n 
 
                         b y t e [ ]   b a   =   B i t C o n v e r t e r . G e t B y t e s ( r e t ) ; 
 
                         A r r a y . R e v e r s e ( b a ) ; 
 
                         r e t u r n   B i t C o n v e r t e r . T o D o u b l e ( b a ,   0 ) ; 
 
 
 
                 } 
 
         } 
 
 } 