/*
CLASS {NATIVE_Stream_on_C_Stream|_Java}, NATIVE :

*/

import java.io.*;

public class NATIVE_Stream_on_C_Stream {
	public static class NATIVE_input_Stream_on_C_Stream extends InputStream
	{
	    C_Stream C_S;
	    
	    public NATIVE_input_Stream_on_C_Stream(C_Stream cs)
	    {
	        C_S = cs;
	    }
	    
	    public static InputStream Stream_from_C_Stream(C_Stream CS)
	    {
	        InputStream RESULT = new NATIVE_input_Stream_on_C_Stream(CS);
	        return RESULT;
	    }
	    
	    @Override
	    public int available()
	    {
	        try {
	        	C_Long_int.St_long R = (C_Long_int.St_long)C_S.M_Size().Obj; 
	            return R.f_Lo;
	        }
	        catch (Exception E) {
	            AL4_system.Any_exception(E);
	            return(0);
	        }
	    }
	    
	    @Override
	    public int read()
	    {
	        try {
	            byte[] buffer = new byte[1];
	            FixAByte dest2 = new FixAByte(buffer, 0, 1);
	            if (C_S.M_Read_bytes(dest2) > 0)
	                return dest2.Get_item(0);
	            else return(0);
	        }
	        catch (Exception E) {
	            AL4_system.Any_exception(E);
	            return(0);
	        }
	    }
	    
	}
	
	public static class NATIVE_output_Stream_on_C_Stream extends OutputStream
	{
	    C_Stream C_S;
	    
	    public NATIVE_output_Stream_on_C_Stream(C_Stream cs)
	    {
	        C_S = cs;
	    }
	    
	    public static OutputStream Stream_from_C_Stream(C_Stream CS)
	    {
	        OutputStream RESULT = new NATIVE_output_Stream_on_C_Stream(CS);
	        return RESULT;
	    }
	    
	    @Override
	    public void write(int Value) {
	    	byte[] b = new byte[4];
	    	b[0] = (byte)Value;
	    	b[1] = (byte)(Value >> 8);
	    	b[2] = (byte)(Value >> 16);
	    	b[3] = (byte)(Value >> 24);
	    	write(b);
	    }
	    
	    @Override
	    public void write(byte[] buffer)
	    {
	        try {
	            FixAByte dest2 = new FixAByte(buffer, 0, buffer.length);
	            C_S.M_Save_bytes(dest2);
	        }
	        catch (Exception E) {
	            AL4_system.Any_exception(E);
	        }
	    }
	    
	}
}
/*
END
*/





