|
1 | 1 | import java.awt.event.WindowAdapter;
|
2 | 2 | import java.awt.event.WindowEvent;
|
3 | 3 | import java.io.ByteArrayOutputStream;
|
| 4 | +import java.io.FileInputStream; |
4 | 5 | import java.io.FileOutputStream;
|
5 | 6 | import java.io.IOException;
|
6 | 7 | import java.io.ObjectInputStream;
|
|
22 | 23 | import java.util.TreeSet;
|
23 | 24 | import java.util.Vector;
|
24 | 25 | import java.util.Random;
|
| 26 | +import java.util.zip.GZIPOutputStream; |
25 | 27 |
|
26 | 28 | import javax.swing.JScrollPane;
|
27 | 29 | import javax.swing.SwingUtilities;
|
@@ -168,10 +170,16 @@ private void writeObject(final ObjectOutputStream oos)
|
168 | 170 |
|
169 | 171 | ObjectOutputStream oos;
|
170 | 172 |
|
| 173 | + /** |
| 174 | + * Returns the name of the file where to serialize the test content |
| 175 | + */ |
| 176 | + private String getTestFileName() { |
| 177 | + return name.getMethodName() + ".ser"; |
| 178 | + } |
| 179 | + |
171 | 180 | @Before
|
172 | 181 | public void setUp() throws Exception {
|
173 |
| - oos = new ObjectOutputStream(fos = new FileOutputStream( |
174 |
| - name.getMethodName() + ".ser")); |
| 182 | + oos = new ObjectOutputStream(fos = new FileOutputStream(getTestFileName())); |
175 | 183 | }
|
176 | 184 |
|
177 | 185 | @Test
|
@@ -208,6 +216,20 @@ public void testChar() throws IOException {
|
208 | 216 | public void testChars() throws IOException {
|
209 | 217 | oos.writeChars("python-javaobj");
|
210 | 218 | oos.close();
|
| 219 | + |
| 220 | + // Also compress the file |
| 221 | + final String serializedFileName = getTestFileName(); |
| 222 | + final String gzippedFileName = serializedFileName + ".gz"; |
| 223 | + |
| 224 | + try (final GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzippedFileName))){ |
| 225 | + try (final FileInputStream in = new FileInputStream(serializedFileName)){ |
| 226 | + final byte[] buffer = new byte[1024]; |
| 227 | + int len; |
| 228 | + while((len = in.read(buffer)) != -1){ |
| 229 | + out.write(buffer, 0, len); |
| 230 | + } |
| 231 | + } |
| 232 | + } |
211 | 233 | }
|
212 | 234 |
|
213 | 235 | @Test
|
@@ -389,7 +411,7 @@ public void windowClosing(final WindowEvent e) {
|
389 | 411 | });
|
390 | 412 | }
|
391 | 413 |
|
392 |
| - |
| 414 | + |
393 | 415 | /**
|
394 | 416 | * Tests the pull request #38 by @UruDev:
|
395 | 417 | * Add support for custom writeObject
|
|
0 commit comments