Skip to content

Commit a2079bf

Browse files
hansonrhansonr
authored andcommitted
file/security classes;exception upgrades
1 parent 658589f commit a2079bf

File tree

404 files changed

+92945
-3549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

404 files changed

+92945
-3549
lines changed
279 KB
Binary file not shown.
28 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190819235053
1+
20190822222839
279 KB
Binary file not shown.
28 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190819235053
1+
20190822222839

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompilationParticipant.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ public void buildStarting(BuildContext[] files, boolean isBatch) {
102102
*/
103103
public void buildFinished(IJavaProject project) {
104104
if (javaFiles != null) {
105-
System.out.println("building JavaScript " + project.getProject().getLocation());
106105
Java2ScriptCompiler j2sCompiler = new Java2ScriptCompiler();
107106
j2sCompiler.startBuild(isCleanBuild);
108-
j2sCompiler.initializeProject(project, true);
107+
if (!j2sCompiler.initializeProject(project, true)) {
108+
System.out.println(".j2s disabled");
109+
return;
110+
}
111+
System.out.println("building JavaScript " + project.getProject().getLocation());
109112
for (int i = 0; i < javaFiles.length; i++) {
110113
System.out.println("transpiling " + javaFiles[i]);
111114
// trying to keep the progess monitor running - didn't work
279 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/io/ByteArrayOutputStream.java

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/*
2-
* Some portions of this file have been modified by Robert Hanson hansonr.at.stolaf.edu 2012-2017
3-
* for use in SwingJS via transpilation into JavaScript using Java2Script.
4-
*
5-
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
63
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74
*
85
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +25,7 @@
2825

2926
package java.io;
3027

31-
import java.io.IOException;
28+
import java.util.Arrays;
3229

3330
/**
3431
* This class implements an output stream in which the data is
@@ -96,6 +93,14 @@ private void ensureCapacity(int minCapacity) {
9693
grow(minCapacity);
9794
}
9895

96+
/**
97+
* The maximum size of array to allocate.
98+
* Some VMs reserve some header words in an array.
99+
* Attempts to allocate larger arrays may result in
100+
* OutOfMemoryError: Requested array size exceeds VM limit
101+
*/
102+
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
103+
99104
/**
100105
* Increases the capacity to ensure that it can hold at least the
101106
* number of elements specified by the minimum capacity argument.
@@ -108,22 +113,19 @@ private void grow(int minCapacity) {
108113
int newCapacity = oldCapacity << 1;
109114
if (newCapacity - minCapacity < 0)
110115
newCapacity = minCapacity;
111-
if (newCapacity < 0) {
112-
if (minCapacity < 0) // overflow
113-
throw new OutOfMemoryError();
114-
newCapacity = minCapacity;
115-
}
116-
buf = arrayCopyByte(buf, newCapacity);
116+
if (newCapacity - MAX_ARRAY_SIZE > 0)
117+
newCapacity = hugeCapacity(minCapacity);
118+
buf = Arrays.copyOf(buf, newCapacity);
117119
}
118120

119-
private static byte[] arrayCopyByte(byte[] array, int newLength) {
120-
byte[] t = new byte[newLength];
121-
System.arraycopy(array, 0, t, 0, array.length < newLength ? array.length
122-
: newLength);
123-
return t;
121+
private static int hugeCapacity(int minCapacity) {
122+
if (minCapacity < 0) // overflow
123+
throw new OutOfMemoryError();
124+
return (minCapacity > MAX_ARRAY_SIZE) ?
125+
Integer.MAX_VALUE :
126+
MAX_ARRAY_SIZE;
124127
}
125128

126-
127129
/**
128130
* Writes the specified byte to this byte array output stream.
129131
*
@@ -187,7 +189,7 @@ public synchronized void reset() {
187189
* @see java.io.ByteArrayOutputStream#size()
188190
*/
189191
public synchronized byte toByteArray()[] {
190-
return (count == buf.length ? buf : arrayCopyByte(buf, count));
192+
return (count == buf.length ? buf : Arrays.copyOf(buf, count)); // BH why copy if buf is fine?
191193
}
192194

193195
/**
@@ -221,39 +223,64 @@ public synchronized String toString() {
221223
return new String(buf, 0, count);
222224
}
223225

224-
// /**
225-
// * Converts the buffer's contents into a string by decoding the bytes using
226-
// * the specified {@link java.nio.charset.Charset charsetName}. The length of
227-
// * the new <tt>String</tt> is a function of the charset, and hence may not be
228-
// * equal to the length of the byte array.
229-
// *
230-
// * <p> This method always replaces malformed-input and unmappable-character
231-
// * sequences with this charset's default replacement string. The {@link
232-
// * java.nio.charset.CharsetDecoder} class should be used when more control
233-
// * over the decoding process is required.
234-
// *
235-
// * @param charsetName the name of a supported
236-
// * {@linkplain java.nio.charset.Charset </code>charset<code>}
237-
// * @return String decoded from the buffer's contents.
238-
// * @exception UnsupportedEncodingException
239-
// * If the named charset is not supported
240-
// * @since JDK1.1
241-
// */
242-
// public synchronized String toString(String charsetName)
243-
// throws UnsupportedEncodingException
244-
// {
245-
// return new String(buf, 0, count, charsetName);
246-
// }
226+
/**
227+
* Converts the buffer's contents into a string by decoding the bytes using
228+
* the named {@link java.nio.charset.Charset charset}. The length of the new
229+
* <tt>String</tt> is a function of the charset, and hence may not be equal
230+
* to the length of the byte array.
231+
*
232+
* <p> This method always replaces malformed-input and unmappable-character
233+
* sequences with this charset's default replacement string. The {@link
234+
* java.nio.charset.CharsetDecoder} class should be used when more control
235+
* over the decoding process is required.
236+
*
237+
* @param charsetName the name of a supported
238+
* {@link java.nio.charset.Charset charset}
239+
* @return String decoded from the buffer's contents.
240+
* @exception UnsupportedEncodingException
241+
* If the named charset is not supported
242+
* @since JDK1.1
243+
*/
244+
public synchronized String toString(String charsetName)
245+
throws UnsupportedEncodingException
246+
{
247+
return new String(buf, 0, count, charsetName);
248+
}
249+
250+
/**
251+
* Creates a newly allocated string. Its size is the current size of
252+
* the output stream and the valid contents of the buffer have been
253+
* copied into it. Each character <i>c</i> in the resulting string is
254+
* constructed from the corresponding element <i>b</i> in the byte
255+
* array such that:
256+
* <blockquote><pre>
257+
* c == (char)(((hibyte &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
258+
* </pre></blockquote>
259+
*
260+
* @deprecated This method does not properly convert bytes into characters.
261+
* As of JDK&nbsp;1.1, the preferred way to do this is via the
262+
* <code>toString(String enc)</code> method, which takes an encoding-name
263+
* argument, or the <code>toString()</code> method, which uses the
264+
* platform's default character encoding.
265+
*
266+
* @param hibyte the high byte of each resulting Unicode character.
267+
* @return the current contents of the output stream, as a string.
268+
* @see java.io.ByteArrayOutputStream#size()
269+
* @see java.io.ByteArrayOutputStream#toString(String)
270+
* @see java.io.ByteArrayOutputStream#toString()
271+
*/
272+
@Deprecated
273+
public synchronized String toString(int hibyte) {
274+
return new String(buf, hibyte, 0, count);
275+
}
247276

248277
/**
249278
* Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
250279
* this class can be called after the stream has been closed without
251280
* generating an <tt>IOException</tt>.
252-
* <p>
253-
*
254281
*/
255282
@Override
256283
public void close() throws IOException {
257284
}
258285

259-
}
286+
}

sources/net.sf.j2s.java.core/src/java/io/DataInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public final String readLine() throws IOException {
565565
if (!(in instanceof PushbackInputStream)) {
566566
this.in = new PushbackInputStream(in, 1);
567567
}
568-
((PushbackInputStream) in).unreadByte(c2);
568+
((PushbackInputStream) in).unread(c2);
569569
}
570570
break loop;
571571

0 commit comments

Comments
 (0)