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

35
LINES

< > BotCompany Repo | #1032933 // ShortInputStream

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

Libraryless. Click here for Pure Java version (3920L/22K).

asclass ShortInputStream {
  public int read(short[] destination) throws IOException {
    ret read(destination, 0, l(destination));
  }
  
  public int read(short[] destination, int off, int len) throws IOException {
    int n = 0;
    while (n < len) {
      int i = read();
      if (i == Int.MIN_VALUE)
        break;
      destination[off+n] = (short) i;
      n++;
    }
    ret n;
  }
  
  public abstract int read() throws IOException;
  
  public void readFully(short[] destination) throws IOException {
    readFully(destination, 0, destination.length);
  }
  
  public void readFully(short[] destination, int offset, int length) throws IOException {
    int read = 0;
     
    while (read < length) {
      int r = read(destination, offset+read, length-read);
      if (r == -1)
        throw new EOFException("Asked to read " + length + " bytes from " + offset + " but hit EoF at " + read);
      else
        read += r;
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032933
Snippet name: ShortInputStream
Eternal ID of this version: #1032933/4
Text MD5: ae1beeb6a4b75b3206795c851a212d26
Transpilation MD5: df443d3f656753baf6d93be2796af33b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 01:41:37
Source code size: 979 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 174 / 286
Version history: 3 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)