~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangBinary.java

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ``The contents of this file are subject to the Erlang Public License,
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 * 
 
4
 * Copyright Ericsson AB 2000-2009. All Rights Reserved.
 
5
 * 
 
6
 * The contents of this file are subject to the Erlang Public License,
2
7
 * Version 1.1, (the "License"); you may not use this file except in
3
8
 * compliance with the License. You should have received a copy of the
4
9
 * Erlang Public License along with this software. If not, it can be
5
 
 * retrieved via the world wide web at http://www.erlang.org/.
 
10
 * retrieved online at http://www.erlang.org/.
6
11
 * 
7
12
 * Software distributed under the License is distributed on an "AS IS"
8
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
14
 * the License for the specific language governing rights and limitations
10
15
 * under the License.
11
16
 * 
12
 
 * The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
 
 * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
 
 * AB. All Rights Reserved.''
15
 
 * 
16
 
 *     $Id$
 
17
 * %CopyrightEnd%
17
18
 */
18
19
package com.ericsson.otp.erlang;
19
20
 
20
21
import java.io.Serializable;
21
 
import java.io.IOException;
22
 
import java.io.ByteArrayInputStream;
23
 
import java.io.ByteArrayOutputStream;
24
 
import java.io.ObjectInputStream;
25
 
import java.io.ObjectOutputStream;
26
22
 
27
23
/**
28
 
 * Provides a Java representation of Erlang binaries. Anything that
29
 
 *  can be represented as a sequence of bytes can be made into an
30
 
 *  Erlang binary.
31
 
 **/
32
 
public class OtpErlangBinary extends OtpErlangBitstr
33
 
    implements Serializable, Cloneable
34
 
{
 
24
 * Provides a Java representation of Erlang binaries. Anything that can be
 
25
 * represented as a sequence of bytes can be made into an Erlang binary.
 
26
 */
 
27
public class OtpErlangBinary extends OtpErlangBitstr implements Serializable,
 
28
        Cloneable {
35
29
    // don't change this!
36
30
    static final long serialVersionUID = -3781009633593609217L;
37
 
    
 
31
 
38
32
    /**
39
33
     * Create a binary from a byte array
40
 
     *
41
 
     * @param bin the array of bytes from which to create the binary.
42
 
     **/
43
 
    public OtpErlangBinary(byte[] bin) {
 
34
     * 
 
35
     * @param bin
 
36
     *                the array of bytes from which to create the binary.
 
37
     */
 
38
    public OtpErlangBinary(final byte[] bin) {
44
39
        super(bin);
45
40
    }
46
 
    
 
41
 
47
42
    /**
48
 
     * Create a binary from a stream containing a binary encoded in
49
 
     * Erlang external format.
50
 
     *
51
 
     * @param buf the stream containing the encoded binary.
52
 
     *
53
 
     * @exception OtpErlangDecodeException if the buffer does not
54
 
     * contain a valid external representation of an Erlang binary.
55
 
     **/
56
 
    public OtpErlangBinary(OtpInputStream buf) throws OtpErlangDecodeException
57
 
    {
 
43
     * Create a binary from a stream containing a binary encoded in Erlang
 
44
     * external format.
 
45
     * 
 
46
     * @param buf
 
47
     *                the stream containing the encoded binary.
 
48
     * 
 
49
     * @exception OtpErlangDecodeException
 
50
     *                    if the buffer does not contain a valid external
 
51
     *                    representation of an Erlang binary.
 
52
     */
 
53
    public OtpErlangBinary(final OtpInputStream buf)
 
54
            throws OtpErlangDecodeException {
58
55
        super(new byte[0]);
59
 
        this.bin = buf.read_binary();
60
 
        this.pad_bits = 0;
 
56
        bin = buf.read_binary();
 
57
        pad_bits = 0;
61
58
    }
62
 
    
 
59
 
63
60
    /**
64
 
     * Create a binary from an arbitrary Java Object. The object must
65
 
     * implement java.io.Serializable or java.io.Externalizable.
66
 
     *
67
 
     * @param o the object to serialize and create this binary from.
68
 
     **/
69
 
    public OtpErlangBinary(Object o) {
 
61
     * Create a binary from an arbitrary Java Object. The object must implement
 
62
     * java.io.Serializable or java.io.Externalizable.
 
63
     * 
 
64
     * @param o
 
65
     *                the object to serialize and create this binary from.
 
66
     */
 
67
    public OtpErlangBinary(final Object o) {
70
68
        super(o);
71
69
    }
72
70
 
73
 
 
74
 
 
75
71
    /**
76
72
     * Convert this binary to the equivalent Erlang external representation.
77
 
     *
78
 
     * @param buf an output stream to which the encoded binary should be
79
 
     * written.
80
 
     **/
81
 
    public void encode(OtpOutputStream buf) {
82
 
        buf.write_binary(this.bin);
83
 
    }
84
 
    
85
 
    /**
86
 
     * Determine if two binaries are equal. Binaries are equal if they have
87
 
     * the same length and the array of bytes is identical.
88
 
     *
89
 
     * @param o the binary to compare to.
90
 
     *
91
 
     * @return true if the byte arrays contain the same bytes, false
92
 
     * otherwise.
93
 
     **/
94
 
    public boolean equals(Object o) {
95
 
        if (! (o instanceof OtpErlangBinary)) return false;
96
 
        
97
 
        OtpErlangBinary that = (OtpErlangBinary)o;
98
 
        int len = this.bin.length;
99
 
        if (len != that.bin.length) return false;
100
 
        
101
 
        for (int i = 0;  i < len;  i++) {
102
 
            if (this.bin[i] != that.bin[i]) return false; // early exit
103
 
        }
104
 
        
105
 
        return true;
106
 
    }
107
 
    
 
73
     * 
 
74
     * @param buf
 
75
     *                an output stream to which the encoded binary should be
 
76
     *                written.
 
77
     */
 
78
    @Override
 
79
    public void encode(final OtpOutputStream buf) {
 
80
        buf.write_binary(bin);
 
81
    }
 
82
 
 
83
    @Override
108
84
    public Object clone() {
109
 
        OtpErlangBinary that = (OtpErlangBinary)(super.clone());
 
85
        final OtpErlangBinary that = (OtpErlangBinary) super.clone();
110
86
        return that;
111
87
    }
112
88
}