Permalink
Browse files

update jinterface to R16A

  • Loading branch information...
1 parent d79c2ff commit f17028227de299a4e9464b9b57a5b39a2c9c2ab7 @vladdu vladdu committed Feb 1, 2013
@@ -1,20 +1,20 @@
/*
* %CopyrightBegin%
- *
+ *
* Copyright Ericsson AB 2000-2009. All Rights Reserved.
- *
+ *
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
* compliance with the License. You should have received a copy of the
* Erlang Public License along with this software. If not, it can be
* retrieved online at http://www.erlang.org/.
- *
+ *
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
- *
- * %CopyrightEnd%
+ *
+ * %CopyrightEnd%
*/
package com.ericsson.otp.erlang;
@@ -90,6 +90,8 @@
static final int dFlagExportPtrTag = 0x200; // NOT SUPPORTED
static final int dFlagBitBinaries = 0x400;
static final int dFlagNewFloats = 0x800;
+ static final int dFlagUnicodeIo = 0x1000;
+ static final int dFlagUtf8Atoms = 0x10000;
int ntype = NTYPE_R6;
int proto = 0; // tcp/ip
@@ -98,7 +100,7 @@
int creation = 0;
int flags = dFlagExtendedReferences | dFlagExtendedPidsPorts
| dFlagBitBinaries | dFlagNewFloats | dFlagFunTags
- | dflagNewFunTags;
+ | dflagNewFunTags | dFlagUtf8Atoms;
/* initialize hostname and default cookie */
static {
@@ -116,17 +118,15 @@
localHost = "localhost";
}
- final String homeDir = getHomeDir();
- final String dotCookieFilename = homeDir + File.separator
- + ".erlang.cookie";
+ final String dotCookieFilename = System.getProperty("user.home")
+ + File.separator + ".erlang.cookie";
BufferedReader br = null;
try {
final File dotCookieFile = new File(dotCookieFilename);
br = new BufferedReader(new FileReader(dotCookieFile));
- final String line = br.readLine();
- defaultCookie = line != null ? line.trim() : line;
+ defaultCookie = br.readLine().trim();
} catch (final IOException e) {
defaultCookie = "";
} finally {
@@ -251,16 +251,4 @@ public String setCookie(final String cookie) {
public String toString() {
return node();
}
-
- private static String getHomeDir() {
- final String u = System.getProperty("user.home");
- if (System.getProperty("os.name").toLowerCase().contains("windows")) {
- final String d = System.getenv("HOMEDRIVE");
- final String p = System.getenv("HOMEPATH");
- return (d != null && p != null) ? d + p : u;
- } else {
- return u;
- }
- }
-
}
@@ -357,7 +357,7 @@ private static Socket r4_publish(final OtpLocalNode node)
}
public static String[] lookupNames() throws IOException {
- return lookupNames(InetAddress.getLocalHost());
+ return lookupNames(InetAddress.getByName(null));
}
public static String[] lookupNames(final InetAddress address)
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 2000-2009. All Rights Reserved.
+ * Copyright Ericsson AB 2000-2012. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -50,7 +50,7 @@ public OtpErlangAtom(final String atom) {
throw new java.lang.IllegalArgumentException("null string value");
}
- if (atom.length() > maxAtomLength) {
+ if (atom.codePointCount(0, atom.length()) > maxAtomLength) {
throw new java.lang.IllegalArgumentException("Atom may not exceed "
+ maxAtomLength + " characters: " + atom);
}
@@ -19,7 +19,6 @@
package com.ericsson.otp.erlang;
import java.io.Serializable;
-import java.util.Arrays;
public class OtpErlangFun extends OtpErlangObject implements Serializable {
// don't change this!
@@ -92,7 +91,7 @@ public boolean equals(final Object o) {
return false;
}
} else {
- if (!Arrays.equals(md5, f.md5)) {
+ if (!md5.equals(f.md5)) {
return false;
}
}
@@ -102,7 +101,7 @@ public boolean equals(final Object o) {
if (freeVars == null) {
return f.freeVars == null;
}
- return Arrays.equals(freeVars, f.freeVars);
+ return freeVars.equals(f.freeVars);
}
@Override
@@ -326,7 +326,7 @@ public Object clone() {
try {
return new OtpErlangList(elements(), getLastTail());
} catch (final OtpErlangException e) {
- throw new AssertionError(e);
+ return null;
}
}
@@ -82,13 +82,13 @@ public OtpErlangTuple(final OtpErlangObject[] elems) {
* @exception java.lang.IllegalArgumentException
* if the array is empty (null) or contains null elements.
*/
- public OtpErlangTuple(final OtpErlangObject[] elems, final int start,
+ public OtpErlangTuple(OtpErlangObject[] elems, final int start,
final int count) {
if (elems == null) {
throw new java.lang.IllegalArgumentException(
"Tuple content can't be null");
} else if (count < 1) {
- this.elems = NO_ELEMENTS;
+ elems = NO_ELEMENTS;
} else {
this.elems = new OtpErlangObject[count];
for (int i = 0; i < count; i++) {
@@ -88,6 +88,12 @@ private OtpExternal() {
/** The tag used for old Funs */
public static final int funTag = 117;
+ /** The tag used for unicode atoms */
+ public static final int atomUtf8Tag = 118;
+
+ /** The tag used for small unicode atoms */
+ public static final int smallAtomUtf8Tag = 119;
+
/** The tag used for compressed terms */
public static final int compressedTag = 80;
@@ -21,7 +21,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigDecimal;
-import java.util.Arrays;
/**
* Provides a stream for decoding Erlang terms from external format.
@@ -352,26 +351,63 @@ public boolean read_boolean() throws OtpErlangDecodeException {
*/
public String read_atom() throws OtpErlangDecodeException {
int tag;
- int len;
+ int len = -1;
byte[] strbuf;
String atom;
tag = read1skip_version();
- if (tag != OtpExternal.atomTag) {
- throw new OtpErlangDecodeException(
- "wrong tag encountered, expected " + OtpExternal.atomTag
- + ", got " + tag);
- }
+ switch (tag) {
- len = read2BE();
+ case OtpExternal.atomTag:
+ len = read2BE();
+ strbuf = new byte[len];
+ this.readN(strbuf);
+ try {
+ atom = new String(strbuf, "ISO-8859-1");
+ } catch (final java.io.UnsupportedEncodingException e) {
+ throw new OtpErlangDecodeException(
+ "Failed to decode ISO-8859-1 atom");
+ }
+ if (atom.length() > OtpExternal.maxAtomLength) {
+ /*
+ * Throwing an exception would be better I think, but truncation
+ * seems to be the way it has been done in other parts of OTP...
+ */
+ atom = atom.substring(0, OtpExternal.maxAtomLength);
+ }
+ break;
- strbuf = new byte[len];
- this.readN(strbuf);
- atom = OtpErlangString.newString(strbuf);
+ case OtpExternal.smallAtomUtf8Tag:
+ len = read1();
+ /* fall through */
+ case OtpExternal.atomUtf8Tag:
+ if (len < 0) {
+ len = read2BE();
+ }
+ strbuf = new byte[len];
+ this.readN(strbuf);
+ try {
+ atom = new String(strbuf, "UTF-8");
+ } catch (final java.io.UnsupportedEncodingException e) {
+ throw new OtpErlangDecodeException(
+ "Failed to decode UTF-8 atom");
+ }
+ if (atom.codePointCount(0, atom.length()) > OtpExternal.maxAtomLength) {
+ /*
+ * Throwing an exception would be better I think, but truncation
+ * seems to be the way it has been done in other parts of OTP...
+ */
+ final int[] cps = OtpErlangString.stringToCodePoints(atom);
+ atom = new String(cps, 0, OtpExternal.maxAtomLength);
+ }
+ break;
- if (atom.length() > OtpExternal.maxAtomLength) {
- atom = atom.substring(0, OtpExternal.maxAtomLength);
+ default:
+ throw new OtpErlangDecodeException(
+ "wrong tag encountered, expected " + OtpExternal.atomTag
+ + ", or " + OtpExternal.atomUtf8Tag + ", got "
+ + tag);
}
return atom;
@@ -782,7 +818,7 @@ public static long byte_array_to_long(final byte[] b, final boolean unsigned)
if (unsigned) {
if (c < 0) {
throw new OtpErlangDecodeException("Value not unsigned: "
- + Arrays.toString(b));
+ + b);
}
while (b[i] == 0) {
i++; // Skip leading zero sign bytes
@@ -807,7 +843,7 @@ public static long byte_array_to_long(final byte[] b, final boolean unsigned)
if (b.length - i > 8) {
// More than 64 bits of value
throw new OtpErlangDecodeException(
- "Value does not fit in long: " + Arrays.toString(b));
+ "Value does not fit in long: " + b);
}
// Convert the necessary bytes
for (v = c < 0 ? -1 : 0; i < b.length; i++) {
@@ -1113,12 +1149,17 @@ public OtpErlangObject read_compressed() throws OtpErlangDecodeException {
final int size = read4BE();
final byte[] buf = new byte[size];
final java.util.zip.InflaterInputStream is = new java.util.zip.InflaterInputStream(
- this);
+ this, new java.util.zip.Inflater(), size);
+ int curPos = 0;
try {
- final int dsize = is.read(buf, 0, size);
- if (dsize != size) {
+ int curRead;
+ while (curPos < size
+ && (curRead = is.read(buf, curPos, size - curPos)) != -1) {
+ curPos += curRead;
+ }
+ if (curPos != size) {
throw new OtpErlangDecodeException("Decompression gave "
- + dsize + " bytes, not " + size);
+ + curPos + " bytes, not " + size);
}
} catch (final IOException e) {
throw new OtpErlangDecodeException("Cannot read from input stream");
@@ -1149,6 +1190,8 @@ public OtpErlangObject read_any() throws OtpErlangDecodeException {
return new OtpErlangLong(this);
case OtpExternal.atomTag:
+ case OtpExternal.smallAtomUtf8Tag:
+ case OtpExternal.atomUtf8Tag:
return new OtpErlangAtom(this);
case OtpExternal.floatTag:
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 2000-2011. All Rights Reserved.
+ * Copyright Ericsson AB 2000-2012. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -31,7 +31,7 @@
* the recipient of the message. When sending messages to other mailboxes, the
* recipient can only respond if the sender includes the pid as part of the
* message contents. The sender can determine his own pid by calling
- * {@link #self self()}.
+ * {@link #self() self()}.
* </p>
*
* <p>
@@ -141,7 +141,7 @@ public synchronized boolean registerName(final String name) {
* Get the registered name of this mailbox.
*
* @return the registered name of this mailbox, or null if the mailbox had
- * no registerd name.
+ * no registered name.
*/
public String getName() {
return name;
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 2000-2009. All Rights Reserved.
+ * Copyright Ericsson AB 2000-2012. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -182,7 +182,7 @@ protected void finalize() {
* Create an unnamed {@link OtpMbox mailbox} that can be used to send and
* receive messages with other, similar mailboxes and with Erlang processes.
* Messages can be sent to this mailbox by using its associated
- * {@link OtpMbox#self pid}.
+ * {@link OtpMbox#self() pid}.
*
* @return a mailbox.
*/
@@ -248,7 +248,7 @@ public void closeMbox(final OtpMbox mbox, final OtpErlangObject reason) {
* Create an named mailbox that can be used to send and receive messages
* with other, similar mailboxes and with Erlang processes. Messages can be
* sent to this mailbox by using its registered name or the associated
- * {@link OtpMbox#self pid}.
+ * {@link OtpMbox#self() pid}.
*
* @param name
* a name to register for this mailbox. The name must be unique
@@ -743,7 +743,6 @@ public int port() {
return port;
}
- @SuppressWarnings("unused")
@Override
public void run() {
Socket newsock = null;
Oops, something went wrong.

0 comments on commit f170282

Please sign in to comment.