/*## (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 class Output {
 private static ClientIf cl;

 public static void set_client(ClientIf c) {
  cl=c;
 }

 public static ClientIf client() {
  return cl;
 }

 public static void flush() throws Throwable {
  cl.flush();
 }

 public static void end() throws Throwable {
  cl.write_int(-1);
  cl.flush();
 }

 public static void text(String s) throws Throwable {
  cl.write_string(s);
 }

 public static void integer(int i) throws Throwable {
  cl.write_int(i);
 }

 public static void data(byte buf[]) throws Throwable {
  cl.write_buf(buf);
 }

 public static void data(byte buf[],int size) throws Throwable {
  for(int i=0;i<size;i++) {
   int val=(int)buf[i];
   cl.write_byte(val&0xff);
  }
 }

 public static void mem(int addr,int size) throws Throwable {
  for(int i=0;i<size;i++) {
   int val=Memory.read_byte(addr+i);
   cl.write_byte(val);
  }
 }

}
