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

17
LINES

< > BotCompany Repo | #1032912 // InputStreamPlusReadFully

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

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

1  
asclass InputStreamPlusReadFully extends InputStream {
2  
  public void readFully(byte[] destination) throws IOException {
3  
    readFully(destination, 0, destination.length);
4  
  }
5  
  
6  
  public void readFully(byte[] destination, int offset, int length) throws IOException {
7  
    int read = 0;
8  
     
9  
    while (read < length) {
10  
      int r = read(destination, offset+read, length-read);
11  
      if (r == -1)
12  
        throw new EOFException("Asked to read " + length + " bytes from " + offset + " but hit EoF at " + read);
13  
      else
14  
        read += r;
15  
    }
16  
  }
17  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1032912
Snippet name: InputStreamPlusReadFully
Eternal ID of this version: #1032912/8
Text MD5: 10e21f637fef184f90b64bd63dff5e38
Transpilation MD5: bf451474177cb756460903523d34d4d5
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-10 21:36:13
Source code size: 567 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 110 / 216
Version history: 7 change(s)
Referenced in: [show references]