/*## (c) SECURITY EXPLORATIONS    2018 poland                                #*/
/*##     http://www.security-explorations.com                                #*/

/* THIS SOFTWARE IS PROTECTED BY DOMESTIC AND INTERNATIONAL COPYRIGHT LAWS    */
/* UNAUTHORISED COPYING OF THIS SOFTWARE IN EITHER SOURCE OR BINARY FORM IS   */
/* EXPRESSLY FORBIDDEN. ANY USE, INCLUDING THE REPRODUCTION, MODIFICATION,    */
/* DISTRIBUTION, TRANSMISSION, RE-PUBLICATION, STORAGE OR DISPLAY OF ANY      */
/* PART OF THE SOFTWARE, FOR COMMERCIAL OR ANY OTHER PURPOSES REQUIRES A      */
/* VALID LICENSE FROM THE COPYRIGHT HOLDER.                                   */

/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS    */
/* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,*/
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    */
/* SECURITY EXPLORATIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  */
/* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE     */
/* SOFTWARE.                                                                  */

import java.lang.*;

public abstract class WrappedInput {
 private int type;

 public WrappedInput() {
  type=-1;
 }

 public abstract int get_byte() throws Throwable;

 public void set_data_type(int t) {
  type=t;
  SrvConnection.set_input_stream_data_type(this,type);
 }

 public boolean read_boolean() throws Throwable {
  int val=get_byte()&0xff;

  if (val!=0) return true;
   else return false;
 }

 public int read_short() throws Throwable {
  int val=(get_byte()&0xff)<<8;
  val|=(get_byte()&0xff)<<0;
  return val;
 }

 public int read_int() throws Throwable {
  int val=(get_byte()&0xff)<<24;
  val|=(get_byte()&0xff)<<16;
  val|=(get_byte()&0xff)<<8;
  val|=(get_byte()&0xff)<<0;
  return val;
 }

 public String read_string() throws Throwable {
  int len=read_int();

  if (len==-1) return null;

  byte str[]=new byte[len];

  for(int i=0;i<len;i++) {
   str[i]=(byte)get_byte();
  }

  return new String(str);
 }

 public String read_string_with_size(int max_size) throws Throwable {
  int len=read_int();

  String str=null;

  if (len<max_size) {
   byte bytes[]=new byte[len];

   for(int i=0;i<len;i++) {
    bytes[i]=(byte)get_byte();
   }

   str=new String(bytes);
  }

  return str;
 }

 public byte[] read_buf() throws Throwable {
  int len=read_int();
  byte b[]=new byte[len];

  for(int i=0;i<len;i++) {
   b[i]=(byte)get_byte();
  }

  return b;
 }

 public byte[] read_buf_with_size(int max_size) throws Throwable {
  int len=read_int();
  byte b[]=null;

  if (len<max_size) {
   b=new byte[len];

   for(int i=0;i<len;i++) {
    b[i]=(byte)get_byte();
   }
  }

  return b;
 }

 public int read_buf(byte b[],int off) throws Throwable {
  int len=read_int();
  for(int i=0;i<len;i++) {
   b[off+i]=(byte)get_byte();
  }

  return len;
 }

}
