117 if (i < 0) break;
118 char c = (char) (((byte) i) & 0xff);
119 sb.append(c);
120 if (c == '\n') return true;
121 }
122 } catch (EOFException e) {
123 // empty
124 }
125 return false;
126 }
127
128 /** Check that written, closed and read */
129 private static void WriteCloseRead() throws Throwable {
130 Random random = new Random(new Date().getTime());
131
132 PairedInputStream pis = new PairedInputStream();
133 InflaterInputStream iis = new InflaterInputStream(pis);
134
135 PairedOutputStream pos = new PairedOutputStream(pis);
136 pis.setPairedOutputStream(pos);
137 DeflaterOutputStream dos = new DeflaterOutputStream(pos, true);
138
139 byte[] data = new byte[random.nextInt(1024 * 1024)];
140 byte[] buf = new byte[data.length];
141 random.nextBytes(data);
142
143 dos.write(data);
144 dos.close();
145 check(readFully(iis, buf, buf.length));
146 check(Arrays.equals(data, buf));
147 }
148
149 private static void check(InputStream is, OutputStream os)
150 throws Throwable
151 {
152 Random random = new Random(new Date().getTime());
153 // Large writes
154 for (int x = 0; x < 200 ; x++) {
155 // byte[] data = new byte[random.nextInt(1024 * 1024)];
156 byte[] data = new byte[1024];
157 byte[] buf = new byte[data.length];
158 random.nextBytes(data);
159
160 os.write(data);
161 os.flush();
162 check(readFully(is, buf, buf.length));
163 check(Arrays.equals(data, buf));
164 }
|
117 if (i < 0) break;
118 char c = (char) (((byte) i) & 0xff);
119 sb.append(c);
120 if (c == '\n') return true;
121 }
122 } catch (EOFException e) {
123 // empty
124 }
125 return false;
126 }
127
128 /** Check that written, closed and read */
129 private static void WriteCloseRead() throws Throwable {
130 Random random = new Random(new Date().getTime());
131
132 PairedInputStream pis = new PairedInputStream();
133 InflaterInputStream iis = new InflaterInputStream(pis);
134
135 PairedOutputStream pos = new PairedOutputStream(pis);
136 pis.setPairedOutputStream(pos);
137
138 byte[] data = new byte[random.nextInt(1024 * 1024)];
139 byte[] buf = new byte[data.length];
140 random.nextBytes(data);
141
142 try (DeflaterOutputStream dos = new DeflaterOutputStream(pos, true)) {
143 dos.write(data);
144 }
145 check(readFully(iis, buf, buf.length));
146 check(Arrays.equals(data, buf));
147 }
148
149 private static void check(InputStream is, OutputStream os)
150 throws Throwable
151 {
152 Random random = new Random(new Date().getTime());
153 // Large writes
154 for (int x = 0; x < 200 ; x++) {
155 // byte[] data = new byte[random.nextInt(1024 * 1024)];
156 byte[] data = new byte[1024];
157 byte[] buf = new byte[data.length];
158 random.nextBytes(data);
159
160 os.write(data);
161 os.flush();
162 check(readFully(is, buf, buf.length));
163 check(Arrays.equals(data, buf));
164 }
|