static byte[] toByteArray(final Object data, final char type) {
        try {
            final java.io.ByteArrayOutputStream byteStream = new java.io.ByteArrayOutputStream();
            final java.io.DataOutputStream dataStream = new java.io.DataOutputStream(
                    byteStream);
            switch (type) {
            case '1':
                for (int i = 0; i < Array.getLength(data); i++) {
                    dataStream.writeByte(Array.getByte(data, i));
                }
                break;
            case 's':
                for (int i = 0; i < Array.getLength(data); i++) {
                    dataStream.writeShort(Array.getShort(data, i));
                }
                break;
            case 'i':
                for (int i = 0; i < Array.getLength(data); i++) {
                    dataStream.writeInt(Array.getInt(data, i));
                }
                break;
            case 'l':
                for (int i = 0; i < Array.getLength(data); i++) {
                    dataStream.writeLong(Array.getLong(data, i));
                }
                break;
            case 'f':
            case 'F':
                for (int i = 0; i < Array.getLength(data); i++) {
                    dataStream.writeFloat(Array.getFloat(data, i));
                }
                break;
            case 'd':
            case 'D':
                for (int i = 0; i < Array.getLength(data); i++) {
                    dataStream.writeDouble(Array.getDouble(data, i));
                }
                break;
            default:
                throw Py.ValueError("typecode must be in [1silfFdDO]");
            }
            return byteStream.toByteArray();
        } catch (final java.io.IOException e) {
            throw Py.RuntimeError("ioexception:" + e.getMessage());
        }
    }