Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9aff277

Browse files
committed
Jmol-SwingJS fixes for Hashtable; efficiencies for DataInputStream
1 parent b84c33d commit 9aff277

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed
Binary file not shown.

sources/net.sf.j2s.java.core/src_4.2/java/io/BufferedInputStream.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ else if (pos >= buffer.length) /* no room left in buffer */
235235
buffer = buf = nbuf;
236236
}
237237
count = pos;
238-
int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
238+
int n = isRead(buffer, pos, buffer.length - pos);
239239
if (n > 0)
240240
count = n + pos;
241241
}
@@ -262,6 +262,8 @@ public synchronized int readByteAsInt() throws IOException {
262262
return getBufIfOpen()[pos++] & 0xff;
263263
}
264264

265+
266+
265267
/**
266268
* Read characters into a portion of an array, reading from the underlying
267269
* stream at most once if necessary.
@@ -279,7 +281,7 @@ private int read1(byte[] b, int off, int len) throws IOException {
279281
bytes into the local buffer. In this way buffered streams will
280282
cascade harmlessly. */
281283
if (len >= getBufIfOpen().length && markpos < 0) {
282-
return getInIfOpen().read(b, off, len);
284+
return isRead(b, off, len);
283285
}
284286
fill();
285287
avail = count - pos;
@@ -291,7 +293,17 @@ private int read1(byte[] b, int off, int len) throws IOException {
291293
return cnt;
292294
}
293295

294-
/**
296+
private int isRead(byte[] b, int off, int len) throws IOException {
297+
InputStream is = getInIfOpen();
298+
/**
299+
* @j2sNative
300+
* if (is.readBAIS) return is.readBAIS(b, off, len);
301+
*/
302+
{}
303+
return is.read(b, off, len);
304+
}
305+
306+
/**
295307
* Reads bytes from this byte-input stream into the specified byte array,
296308
* starting at the given offset.
297309
*
@@ -332,6 +344,10 @@ private int read1(byte[] b, int off, int len) throws IOException {
332344
public synchronized int read(byte b[], int off, int len)
333345
throws IOException
334346
{
347+
return readBIS(b, off, len);
348+
}
349+
350+
public int readBIS(byte[] b, int off, int len) throws IOException {
335351
getBufIfOpen(); // Check for closed stream
336352
if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
337353
throw new IndexOutOfBoundsException();
@@ -352,9 +368,9 @@ public synchronized int read(byte b[], int off, int len)
352368
if (input != null && input.available() <= 0)
353369
return n;
354370
}
355-
}
371+
}
356372

357-
/**
373+
/**
358374
* See the general contract of the <code>skip</code>
359375
* method of <code>InputStream</code>.
360376
*

sources/net.sf.j2s.java.core/src_4.2/java/io/ByteArrayInputStream.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public synchronized int readByteAsInt() {
178178
*/
179179
@Override
180180
public synchronized int read(byte b[], int off, int len) {
181+
return readBAIS(b, off, len);
182+
}
183+
184+
public int readBAIS(byte[] b, int off, int len) {
181185
if (b == null) {
182186
throw new NullPointerException();
183187
} else if (off < 0 || len < 0 || len > b.length - off) {
@@ -198,9 +202,9 @@ public synchronized int read(byte b[], int off, int len) {
198202
System.arraycopy(buf, pos, b, off, len);
199203
pos += len;
200204
return len;
201-
}
205+
}
202206

203-
/**
207+
/**
204208
* Skips <code>n</code> bytes of input from this input stream. Fewer
205209
* bytes might be skipped if the end of the input stream is reached.
206210
* The actual number <code>k</code>

sources/net.sf.j2s.java.core/src_4.2/java/io/DataInputStream.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ public final int read(byte b[], int off, int len) throws IOException {
161161
return in.read(b, off, len);
162162
}
163163

164+
public final int readDIS(byte b[], int off, int len) throws IOException {
165+
InputStream is = this.in;
166+
/**
167+
* @j2sNative
168+
*
169+
* if (is.readBIS) return is.readBIS(b, off, len);
170+
* if (is.readBAIS)
171+
* return is.readBAIS(b, off, len);
172+
*/
173+
{
174+
}
175+
return is.read(b, off, len);
176+
}
177+
164178
// /**
165179
// * See the general contract of the <code>readFully</code> method of
166180
// * <code>DataInput</code>.

sources/net.sf.j2s.java.core/src_4.2/java/util/Hashtable.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,10 @@ public T nextElement() {
13151315

13161316
@Override
13171317
public Object setValue(Object value) {
1318-
return ht.put(getKey(), value);
1318+
int m = ht.modCount;
1319+
Object v = ht.put(getKey(), value);
1320+
ht.modCount = m;
1321+
return (T) v;
13191322
}
13201323
};
13211324
}

sources/net.sf.j2s.java.core/src_4.2/test/Test.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.awt.event.MouseAdapter;
44
import java.awt.event.MouseEvent;
55
import java.awt.event.MouseListener;
6+
import java.io.ByteArrayInputStream;
7+
import java.io.DataInputStream;
8+
import java.io.IOException;
69

710
public class Test implements ITest {
811

@@ -59,7 +62,17 @@ public Test(){
5962
public final static void main(String[] args) {
6063

6164
new javax.swing.JButton();
62-
65+
66+
ByteArrayInputStream bis = new ByteArrayInputStream(new byte[] {'t','e','s','t'});
67+
DataInputStream dis = new DataInputStream(bis);
68+
byte[] bytes = new byte[4];
69+
try {
70+
dis.read(bytes, 0, 4);
71+
} catch (IOException e1) {
72+
// TODO Auto-generated catch block
73+
e1.printStackTrace();
74+
}
75+
6376
char ch = '1';
6477
switch (ch) {
6578
case 0b111111:

0 commit comments

Comments
 (0)