Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

public class Main {
    public static byte[] getResponeData(int index, int resultCode, String response) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(index);
        outputStream.write(0);
        outputStream.write(resultCode);
        try {
            outputStream.write(response.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return outputStream.toByteArray();
    }

    public static byte[] getResponeData(int index, int resultCode, byte[] response) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(index);
        outputStream.write(1);
        outputStream.write(resultCode);
        try {
            outputStream.write(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return outputStream.toByteArray();
    }
}