package mapped;

import java.io.IOException;
import java.net.Socket;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSBufferedNetSocket;

@ObfuscatedName("re")
public class BufferedNetSocket extends AbstractSocket implements RSBufferedNetSocket {
   @ObfuscatedName("at")
   Socket socket;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lra;"
   )
   BufferedSource source;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Lrs;"
   )
   BufferedSink sink;

   BufferedNetSocket(Socket var1, int var2, int var3) throws IOException {
      this.socket = var1;
      this.socket.setSoTimeout(30000);
      this.socket.setTcpNoDelay(true);
      this.socket.setReceiveBufferSize(65536);
      this.socket.setSendBufferSize(65536);
      this.source = new BufferedSource(this.socket.getInputStream(), var2);
      this.sink = new BufferedSink(this.socket.getOutputStream(), var3);
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Z",
      garbageValue = "278911957"
   )
   public boolean isAvailable_base(int var1) throws IOException {
      return this.source.isAvailable_base(var1);
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "1133909296"
   )
   public int available_base() throws IOException {
      return this.source.available_base();
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-1251290768"
   )
   public int readUnsignedByte_base() throws IOException {
      return this.source.readUnsignedByte_base();
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "([BIIB)I",
      garbageValue = "-54"
   )
   public int read_base(byte[] var1, int var2, int var3) throws IOException {
      return this.source.read_base(var1, var2, var3);
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "([BIII)V",
      garbageValue = "-1981684875"
   )
   public void write_base(byte[] var1, int var2, int var3) throws IOException {
      this.sink.write_base(var1, var2, var3);
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "1195407219"
   )
   public void close_base() {
      this.sink.close_base();

      try {
         this.socket.close();
      } catch (IOException var2) {
         ;
      }

      this.source.close_base();
   }

   protected void finalize() {
      this.close_base();
   }
}
