View Javadoc

1   package com.atlassian.httpclient.apache.httpcomponents;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   import java.nio.charset.Charset;
6   
7   public class GeneratingInputStream extends InputStream {
8       private final long maxLength;
9       private final byte data;
10  
11      private long counter;
12  
13      public GeneratingInputStream(char character, long maxLength) {
14          this.maxLength = maxLength;
15          this.data = String.valueOf(character).getBytes(Charset.forName("UTF-8"))[0];
16      }
17  
18      @Override
19      public int read() throws IOException {
20          if (++counter <= maxLength) {
21              return data;
22          } else {
23              return -1;
24          }
25      }
26  }