Skip to main content
summaryrefslogtreecommitdiffstats
blob: f52c4e2983fa26116464878b1a1007f6e052c1f8 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * Copyright (c) 2007-2013 Eike Stepper (Berlin, Germany) and others.
 * 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.io;

import org.eclipse.net4j.util.io.ExtendedIOUtil.ClassResolver;

import java.io.DataInput;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author Eike Stepper
 * @noextend This interface is not intended to be extended by clients.
 * @noimplement This interface is not intended to be implemented by clients.
 */
public interface ExtendedDataInput extends DataInput
{
  public byte[] readByteArray() throws IOException;

  public Object readObject() throws IOException;

  public Object readObject(ClassLoader classLoader) throws IOException;

  public Object readObject(ClassResolver classResolver) throws IOException;

  public String readString() throws IOException;

  /**
   * @since 3.0
   */
  public <T extends Enum<?>> T readEnum(Class<T> type) throws IOException;

  /**
   * @since 3.4
   */
  public Throwable readException() throws IOException;

  /**
   * @author Eike Stepper
   * @since 2.0
   */
  public static class Delegating implements ExtendedDataInput
  {
    private ExtendedDataInput delegate;

    public Delegating(ExtendedDataInput delegate)
    {
      this.delegate = delegate;
    }

    public ExtendedDataInput getDelegate()
    {
      return delegate;
    }

    public boolean readBoolean() throws IOException
    {
      return delegate.readBoolean();
    }

    public byte readByte() throws IOException
    {
      return delegate.readByte();
    }

    public byte[] readByteArray() throws IOException
    {
      return delegate.readByteArray();
    }

    public char readChar() throws IOException
    {
      return delegate.readChar();
    }

    public double readDouble() throws IOException
    {
      return delegate.readDouble();
    }

    public float readFloat() throws IOException
    {
      return delegate.readFloat();
    }

    public void readFully(byte[] b, int off, int len) throws IOException
    {
      delegate.readFully(b, off, len);
    }

    public void readFully(byte[] b) throws IOException
    {
      delegate.readFully(b);
    }

    public int readInt() throws IOException
    {
      return delegate.readInt();
    }

    public String readLine() throws IOException
    {
      return delegate.readLine();
    }

    public long readLong() throws IOException
    {
      return delegate.readLong();
    }

    public Object readObject() throws IOException
    {
      return delegate.readObject();
    }

    public Object readObject(ClassLoader classLoader) throws IOException
    {
      return delegate.readObject(classLoader);
    }

    public Object readObject(ClassResolver classResolver) throws IOException
    {
      return delegate.readObject(classResolver);
    }

    public short readShort() throws IOException
    {
      return delegate.readShort();
    }

    public String readString() throws IOException
    {
      return delegate.readString();
    }

    /**
     * @since 3.0
     */
    public <T extends Enum<?>> T readEnum(Class<T> type) throws IOException
    {
      return delegate.readEnum(type);
    }

    /**
     * @since 3.4
     */
    public Throwable readException() throws IOException
    {
      return delegate.readException();
    }

    public int readUnsignedByte() throws IOException
    {
      return delegate.readUnsignedByte();
    }

    public int readUnsignedShort() throws IOException
    {
      return delegate.readUnsignedShort();
    }

    public String readUTF() throws IOException
    {
      return delegate.readUTF();
    }

    public int skipBytes(int n) throws IOException
    {
      return delegate.skipBytes(n);
    }
  }

  /**
   * @author Eike Stepper
   * @since 2.0
   */
  public static class Stream extends InputStream
  {
    private ExtendedDataInput delegate;

    public Stream(ExtendedDataInput delegate)
    {
      this.delegate = delegate;
    }

    public ExtendedDataInput getDelegate()
    {
      return delegate;
    }

    @Override
    public int read() throws IOException
    {
      try
      {
        return delegate.readUnsignedByte();
      }
      catch (EOFException ex)
      {
        return -1;
      }
    }
  }
}

Back to the top