/* (non-Javadoc)
@see tuwien.auto.calimero.knxnetip.util.DIB#toByteArray()
427419
public byte[] toByteArray()
	{
		final byte[] buf = super.toByteArray();
		int i = 2;
		for (final Iterator it = map.entrySet().iterator(); it.hasNext();) {
			final Map.Entry e = (Map.Entry) it.next();
			buf[i++] = ((Short) e.getKey()).byteValue();
			buf[i++] = ((Short) e.getValue()).byteValue();
		}
		return buf;
	}
486527
public byte[] toByteArray()
	{
		final byte[] buf = super.toByteArray();
		int i = 2;
		buf[i++] = (byte) knxmedium;
		buf[i++] = (byte) devicestatus;
		final byte[] addr = address.toByteArray();
		buf[i++] = addr[0];
		buf[i++] = addr[1];
		buf[i++] = (byte) (projectInstallID >> 8);
		buf[i++] = (byte) projectInstallID;
		for (int k = 0; k < 6; ++k)
			buf[i++] = serial[k];
		for (int k = 0; k < 4; ++k)
			buf[i++] = mcaddress[k];
		for (int k = 0; k < 6; ++k)
			buf[i++] = mac[k];
		for (int k = 0; k < name.length(); ++k)
			buf[i++] = (byte) name.charAt(k);
		return buf;
	}
1140028
public byte[] toByteArray()
	{
		final ByteArrayOutputStream os = new ByteArrayOutputStream();
		os.write(headersize);
		os.write(version);
		os.write(service >> 8);
		os.write(service);
		os.write(totalsize >> 8);
		os.write(totalsize);
		return os.toByteArray();
	}
649022
@Override
    public byte[] toBytes(Object object)
    {
        if (object == null)
        {
            return null;
        }
        BigInteger b = (BigInteger) object;
        return b.toByteArray();
    }
325977
public byte[] toBytes(@Nullable Object val)
  {
    if (val != null) {
      byte[] bytes = getObjectStrategy().toBytes(val);
      return bytes != null ? bytes : ByteArrays.EMPTY_ARRAY;
    } else {
      return ByteArrays.EMPTY_ARRAY;
    }
  }
728237
public static byte[] toByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            byte[] b = new byte[BUFFER_SIZE];
            int n = 0;
            while ((n = is.read(b)) != -1) {
                output.write(b, 0, n);
            }
            return output.toByteArray();
        } finally {
            output.close();
        }
    }
162307
public byte[] toByteArray() {
    switch (this.repr) {
      case P2:
      case P3:
        FieldElement recip = Z.invert();
        FieldElement x = X.multiply(recip);
        FieldElement y = Y.multiply(recip);
        byte[] s = y.toByteArray();
        s[s.length - 1] |= (x.isNegative() ? (byte) 0x80 : 0);
        return s;
      default:
        return toP2().toByteArray();
    }
  }
1297690
public byte[] toByteArray() throws IOException {
        DerOutputStream out = new DerOutputStream();

        encode(out);
        data.reset();
        return out.toByteArray();
    }
1232169
public static byte[] toBytes(int value) {
		final byte[] result = new byte[4];

		result[0] = (byte) (value >> 24);
		result[1] = (byte) (value >> 16);
		result[2] = (byte) (value >> 8);
		result[3] = (byte) (value /* >> 0 */);

		return result;
	}
950541
byte[] toByteArray(ByteArrayOutputStream os)
	{
		os.write(CONN_HEADER_SIZE);
		os.write(channelid);
		os.write(seq);
		os.write(0);
		final byte[] buf = cemi.toByteArray();
		os.write(buf, 0, buf.length);
		return os.toByteArray();
	}
1246856
public byte[] toByteArray() throws IOException {
		ByteArrayWriter baw = new ByteArrayWriter();

		try {
			baw.writeInt(flags);

			if (version > 3)
				baw.write(type);

			if (isFlagSet(SSH_FILEXFER_ATTR_SIZE)) {
				baw.write(size.toByteArray());
			}

			if (version <= 3 && isFlagSet(SSH_FILEXFER_ATTR_UIDGID)) {
				if (uid != null) {
					try {
						baw.writeInt(Long.parseLong(uid));
					} catch (NumberFormatException ex) {
						baw.writeInt(0);
					}
				} else {
					baw.writeInt(0);
				}

				if (gid != null) {
					try {
						baw.writeInt(Long.parseLong(gid));
					} catch (NumberFormatException ex) {
						baw.writeInt(0);
					}
				} else {
					baw.writeInt(0);
				}
			} else if (version > 3 && isFlagSet(SSH_FILEXFER_ATTR_OWNERGROUP)) {
				if (uid != null)
					baw.writeString(uid, sftp.getCharsetEncoding());
				else
					baw.writeString("");

				if (gid != null)
					baw.writeString(gid, sftp.getCharsetEncoding());
				else
					baw.writeString("");
			}

			if (isFlagSet(SSH_FILEXFER_ATTR_PERMISSIONS)) {
				baw.writeInt(permissions.longValue());
			}

			if (version <= 3 && isFlagSet(SSH_FILEXFER_ATTR_ACCESSTIME)) {
				baw.writeInt(atime.longValue());
				baw.writeInt(mtime.longValue());
			} else if (version > 3) {

				if (isFlagSet(SSH_FILEXFER_ATTR_ACCESSTIME)) {
					baw.writeUINT64(atime);
				}

				if (isFlagSet(SSH_FILEXFER_ATTR_SUBSECOND_TIMES)) {
					baw.writeUINT32(atime_nano);
				}

				if (isFlagSet(SSH_FILEXFER_ATTR_CREATETIME)) {
					baw.writeUINT64(createtime);
				}

				if (isFlagSet(SSH_FILEXFER_ATTR_SUBSECOND_TIMES)) {
					baw.writeUINT32(createtime_nano);
				}

				if (isFlagSet(SSH_FILEXFER_ATTR_MODIFYTIME)) {
					baw.writeUINT64(mtime);
				}

				if (isFlagSet(SSH_FILEXFER_ATTR_SUBSECOND_TIMES)) {
					baw.writeUINT32(mtime_nano);
				}

			}

			if (isFlagSet(SSH_FILEXFER_ATTR_ACL)) {
				ByteArrayWriter tmp = new ByteArrayWriter();

				try {
					Enumeration<ACL> e = acls.elements();
					tmp.writeInt(acls.size());
					while (e.hasMoreElements()) {
						ACL acl = e.nextElement();
						tmp.writeInt(acl.getType());
						tmp.writeInt(acl.getFlags());
						tmp.writeInt(acl.getMask());
						tmp.writeString(acl.getWho());
					}

					baw.writeBinaryString(tmp.toByteArray());
				} finally {
					tmp.close();
				}
			}

			if (isFlagSet(SSH_FILEXFER_ATTR_EXTENDED)) {
				baw.writeInt(extendedAttributes.size());
				Enumeration<String> e = extendedAttributes.keys();
				while (e.hasMoreElements()) {
					String key = e.nextElement();
					baw.writeString(key);
					baw.writeBinaryString(extendedAttributes.get(key));
				}
			}

			return baw.toByteArray();
		} finally {
			try {
				baw.close();
			} catch (IOException e) {
			}
		}
	}
265669
public byte[] toByteArray(int start, int end) {
        return Arrays.copyOfRange(value, start + offset, end + offset);
    }
423448
private static byte[] toByteArray(InputStream is) throws IOException {
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
      byte[] buffer = new byte[0x2000];
      for (int len; (len = is.read(buffer)) != -1; )
        os.write(buffer, 0, len);
      return os.toByteArray();
    }
  }
744305
public byte[] toByteArray() {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(32);

        outputStream.write(commandByte);

        if (serialize(outputStream)) {
            return outputStream.toByteArray();
        }

        return null;
    }
1089156
public static byte[] toByteArray(Streamable streamable) {
        try {
            final ByteArrayOutputStream baos = new ByteArrayOutputStream(streamable.size());
            final DataOutputStream dos = new DataOutputStream(baos);
            streamable.write(dos);
            dos.flush();
            baos.close();
            return baos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
894098
private static byte[] toByteArray(InputStream input) throws IOException {
    try {
      // safe and fast even if input.available() behaves weird or buggy
      int len = Math.max(256, input.available());
      byte[] buffer = new byte[len];
      byte[] output = new byte[len];
      
      len = 0;
      int n;
      while ((n = input.read(buffer)) >= 0) {
        if (len + n > output.length) { // grow capacity
          byte tmp[] = new byte[Math.max(output.length << 1, len + n)];
          System.arraycopy(output, 0, tmp, 0, len);
          System.arraycopy(buffer, 0, tmp, len, n);
          buffer = output; // use larger buffer for future larger bulk reads
          output = tmp;
        } else {
          System.arraycopy(buffer, 0, output, len, n);
        }
        len += n;
      }

      if (len == output.length) return output;
      buffer = null; // help gc
      buffer = new byte[len];
      System.arraycopy(output, 0, buffer, 0, len);
      return buffer;
    } finally {
      input.close();
    }
  }
6165
public function toByte()
    {

        $size = $this->size();

        if($size == 0) {
            return array();
        }

        $data = array_fill(0, (int)(($size + 7) / 8), 0);
        $bytes = (int)($size / 8);

        $p = 0;

        for($i=0; $i<$bytes; $i++) {
            $v = 0;
            for($j=0; $j<8; $j++) {
                $v = $v << 1;
                $v |= $this->data[$p];
                $p++;
            }
            $data[$i] = $v;
        }

        if($size & 7) {
            $v = 0;
            for($j=0; $j<($size & 7); $j++) {
                $v = $v << 1;
                $v |= $this->data[$p];
                $p++;
            }
            $data[$bytes] = $v;
        }

        return $data;
    }