用户:洞穴夜莺/EInputStream:修订间差异
无编辑摘要 |
小 (洞穴夜莺移动页面用户:洞穴夜莺至用户:洞穴夜莺/EInputStream) |
||
| (未显示同一用户的2个中间版本) | |||
| 第2行: | 第2行: | ||
{{eee}} | {{eee}} | ||
<div><div style="height: 30px; background-color: #4e5254; width: 110px; color: #bbbbbb; padding: 0px 10px; position: relative;">EInputStream.java<div style="position: absolute;left: 0px;right: 0px;bottom: 0px;top: 25px;background: #747a80;"></div></div> | |||
<div style="white-space: pre; background-color: #2b2b2b; color: #a9b7c6; margin-top: -10px;"><div style="margin: 10px;"> | <div><div style="height: 30px; background-color: #4e5254; width: 110px; color: #bbbbbb; padding: 0px 10px; position: relative;">EInputStream.java<div style="position: absolute;left: 0px;right: 0px;bottom: 0px;top: 25px;background: #747a80; font-family: mono;"></div></div> | ||
<div style="white-space: pre; background-color: #2b2b2b; color: #a9b7c6; margin-top: -10px; font-family: mono;"><div style="margin: 10px;"> | |||
<span style="color: #cc7832;">import</span> java.io.IOException<span style="color: #cc7832;">;</span> | <span style="color: #cc7832;">import</span> java.io.IOException<span style="color: #cc7832;">;</span> | ||
<span style="color: #cc7832;">import</span> java.io.InputStream<span style="color: #cc7832;">;</span> | <span style="color: #cc7832;">import</span> java.io.InputStream<span style="color: #cc7832;">;</span> | ||
2021年7月19日 (一) 10:22的最新版本
这个用户就是洞穴夜莺
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
/** * You can read nothing but infinite 'e' from an EInputStream * Example: * new EInputStream().transferTo(stdout); * @author CaveNightingale */ public class EInputStream extends InputStream { private static final byte[] BUFFER = new byte[8192]; static { for(int i = 0; i < BUFFER.length; i++) BUFFER[i] = (byte)'e'; }
@Override public int read() { return 'e'; }
@Override public int read(byte[] b) { for(int i = 0; i < b.length; i++) b[i] = (byte)'e'; return b.length; }
@Override public byte[] readAllBytes() { throw new OutOfMemoryError("Endless"); }
@Override public int read(byte[] b, int off, int len) { for(int i = off; i < len + off; i++) b[i] = (byte)'e'; return len; }
@Override public byte[] readNBytes(int len) { byte[] rval = new byte[len]; read(rval); return rval; }
@Override public int readNBytes(byte[] b, int off, int len) { return read(b, off, len); }
@Override public long skip(long n) { return n; }
@Override public long transferTo(OutputStream out) throws IOException { while(true) out.write(BUFFER); }
}