Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1018464 - toByteArray

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4702L/26K).

static byte[] toByteArray(ByteArrayOutputStream baos) {
  ret baos == null ? null : baos.toByteArray();
}

static byte[] toByteArray(Iterator<? extends Number> it) {
  new ByteBuffer buf;
  while (it.hasNext())
    buf.add((byte) it.next().intValue());
  ret buf.toByteArray();
}

static byte[] toByteArray(Cl<? extends Number> it) {
  int n = l(it), i = 0;
  byte[] a = new[n];
  for (x : it)
    a[i++] = (byte) x.intValue();
  ret a;
}

static byte[] toByteArray(O o) {
  if (o == null) null;
  if (o cast byte[]) ret o;
  if (o instanceof Iterator)
    ret toByteArray((Iterator<Number>) o);
  if (o cast Cl)
    ret toByteArray((Cl<Number>) o);
  // not sure what else to put here
  fail("toByteArray", o);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018464
Snippet name: toByteArray
Eternal ID of this version: #1018464/8
Text MD5: 4f5da2eb284a0f739189c30b575c45e5
Transpilation MD5: dc0cf74a5c9eeecbf86b485d0b470496
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-14 04:24:40
Source code size: 741 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 193 / 259
Version history: 7 change(s)
Referenced in: [show references]