Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static byte[] postWork(byte[] ar, String type, int len) {
        byte[] res = new byte[len];
        for (int i = 0; i < len; i++)
            res[i] = 0;
        int l = ar.length;
        if (type.equals("LONG"))
            for (int i = 0; i < l; i++)
                res[i] = ar[l - i - 1];
        if (type.equals("INT"))
            for (int i = 0; i < l; i++)
                res[i] = ar[l - i - 1];
        if (type.equals("STRING"))
            if (isUnicode(ar))
                for (int i = 1; i < l; i = i + 2)
                    res[(i - 1) / 2] = ar[i];
            else
                System.arraycopy(ar, 0, res, 0, l);
        if (type.equals("DATE"))
            for (int i = 0; i < l; i++)
                res[i] = ar[l - i - 1];
        if (type.equals("CHR"))
            System.arraycopy(ar, 0, res, 0, l);
        if (type.equals("UCHR"))
            System.arraycopy(ar, 0, res, 0, l);
        if (type.equals("NUMERIC"))
            System.arraycopy(ar, 0, res, 0, l);

        return res;
    }

    public static boolean isUnicode(byte[] ar) {

        if (ar.length % 2 == 1)
            return false;
        for (int i = 0; i < ar.length; i = i + 2)
            if (ar[i] != -48)
                return false;

        return true;
    }
}