Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ec49ac358fc1ec74441a69f430f4a341543e5ce7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/***************************************************************************
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.net4j.util.tests;

import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;

/**
 * @author Eike Stepper
 */
public class ExtendedIOTest extends AbstractOMTest
{
  @SuppressWarnings("unchecked")
  public void testObject() throws Exception
  {
    final HashMap<String, String> map = createMap();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
    edos.writeObject(map);
    edos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
    HashMap<String, String> result = (HashMap<String, String>)edis.readObject();
    assertEquals(map, result);
  }

  public void testByteArray() throws Exception
  {
    final byte[] byteArray = createByteArray();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
    edos.writeByteArray(byteArray);
    edos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
    byte[] result = edis.readByteArray();
    assertTrue(Arrays.equals(byteArray, result));
  }

  private byte[] createByteArray() throws IOException
  {
    HashMap<String, String> map = createMap();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
    edos.writeObject(map);
    edos.close();
    return baos.toByteArray();
  }

  private HashMap<String, String> createMap()
  {
    HashMap<String, String> map = new HashMap<String, String>();
    putMap(map, "org.eclipse.net4j.util.io.CachedFileMap.java");
    putMap(map, "org.eclipse.net4j.util.io.CloseableIterator.java");
    putMap(map, "org.eclipse.net4j.util.io.DataInputExtender.java");
    putMap(map, "org.eclipse.net4j.util.io.DataOutputExtender.java");
    putMap(map, "org.eclipse.net4j.util.io.DelegatingInputStream.java");
    putMap(map, "org.eclipse.net4j.util.io.DelegatingOutputStream.java");
    putMap(map, "org.eclipse.net4j.util.io.DelegatingStreamWrapper.java");
    putMap(map, "org.eclipse.net4j.util.io.ExtendedDataInput.java");
    putMap(map, "org.eclipse.net4j.util.io.ExtendedDataInputStream.java");
    putMap(map, "org.eclipse.net4j.util.io.ExtendedDataOutput.java");
    putMap(map, "org.eclipse.net4j.util.io.ExtendedDataOutputStream.java");
    putMap(map, "org.eclipse.net4j.util.io.ExtendedIOUtil.java");
    putMap(map, "org.eclipse.net4j.util.io.GZIPStreamWrapper.java");
    putMap(map, "org.eclipse.net4j.util.io.IOFilter.java");
    putMap(map, "org.eclipse.net4j.util.io.IORunnable.java");
    putMap(map, "org.eclipse.net4j.util.io.IORuntimeException.java");
    putMap(map, "org.eclipse.net4j.util.io.IOUtil.java");
    putMap(map, "org.eclipse.net4j.util.io.IOVisitor.java");
    putMap(map, "org.eclipse.net4j.util.io.IStreamWrapper.java");
    putMap(map, "org.eclipse.net4j.util.io.NIOUtil.java");
    putMap(map, "org.eclipse.net4j.util.io.SortedFileMap.java");
    putMap(map, "org.eclipse.net4j.util.io.StreamWrapperChain.java");
    putMap(map, "org.eclipse.net4j.util.io.TMPUtil.java");
    putMap(map, "org.eclipse.net4j.util.io.XORInputStream.java");
    putMap(map, "org.eclipse.net4j.util.io.XOROutputStream.java");
    putMap(map, "org.eclipse.net4j.util.io.XORStreamWrapper.java");
    putMap(map, "org.eclipse.net4j.util.io.ZIPUtil.java");
    return map;
  }

  private void putMap(HashMap<String, String> map, String string)
  {
    map.put(string, string);
  }
}

Back to the top