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

29
LINES

< > BotCompany Repo | #1036592 // LimitedOutputStream - OutputStream that fails when writing too much

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

Libraryless. Click here for Pure Java version (10729L/59K).

sclass LimitedOutputStream extends CountingOutputStream {
  long limit;
  
  *(OutputStream out) { super(out); }
  *(OutputStream out, long *limit) { super(out); }
  
  @Override
  public void write(int b) throws IOException {
    checkLimit();
    super.write(b);
  }

  @Override
  public void write(byte[] b) throws IOException {
    checkLimit();
    super.write(b);
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    checkLimit();
    super.write(b, off, len);
  }
  
  void checkLimit {
    if (counter >= limit)
      fail("Write limit reached (" + n2(limit) + " bytes)");
  }
}

Author comment

Began life as a copy of #1029366

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036592
Snippet name: LimitedOutputStream - OutputStream that fails when writing too much
Eternal ID of this version: #1036592/3
Text MD5: 34f1141d6c9a0a0f526b57a332e8adce
Transpilation MD5: b9bccc7ba4b7d1efa70ddc67f3552b1b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-04-02 18:22:30
Source code size: 652 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 76 / 116
Version history: 2 change(s)
Referenced in: [show references]