app/src/main/java/com/isode/stroke/base/ByteArray.java
author Da Risk <da_risk@beem-project.com>
Sun, 15 Mar 2015 18:03:03 +0100
changeset 1044 197a85a35cba
parent 1018 src/com/isode/stroke/base/ByteArray.java@8daca77fabc1
permissions -rw-r--r--
Move the app into an app submodule which respect the default gradle layout
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1015
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     1
/*
1018
8daca77fabc1 fix Remko's currly part of name
Jiří Pinkava <j-pi@seznam.cz>
parents: 1015
diff changeset
     2
 * Copyright (c) 2010 Remko Tronçon
1015
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     3
 * Licensed under the GNU General Public License v3.
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     4
 * See Documentation/Licenses/GPLv3.txt for more information.
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     5
 */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     6
/*
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     7
 * Copyright (c) 2010, Isode Limited, London, England.
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     8
 * All rights reserved.
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
     9
 */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    10
package com.isode.stroke.base;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    11
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    12
import java.io.UnsupportedEncodingException;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    13
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    14
/**
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    15
 *
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    16
 */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    17
public class ByteArray {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    18
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    19
    public ByteArray() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    20
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    21
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    22
    public ByteArray(String s) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    23
        try {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    24
            fromBytes(s.getBytes("UTF-8"));
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    25
        } catch (UnsupportedEncodingException ex) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    26
            throw new IllegalStateException("JVM has no 'UTF-8' encoding");
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    27
        }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    28
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    29
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    30
    public ByteArray(byte[] c) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    31
        fromBytes(c);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    32
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    33
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    34
    public ByteArray(ByteArray b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    35
        fromBytes(b.getData());
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    36
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    37
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    38
    private void fromBytes(final byte[] b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    39
        data_ = new byte[b.length];
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    40
        System.arraycopy(b, 0, data_, 0, b.length);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    41
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    42
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    43
    /*public ByteArray(char[] c, int n) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    44
        for (int i = 0; i < n; i++) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    45
            append(c[i]);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    46
        }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    47
    }*/
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    48
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    49
    /**
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    50
     * These are the raw, modifyable data!
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    51
     * @return
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    52
     */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    53
    public byte[] getData() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    54
        return data_;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    55
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    56
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    57
    public int getSize() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    58
        return data_.length;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    59
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    60
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    61
    public boolean isEmpty() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    62
        return getSize() == 0;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    63
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    64
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    65
    /*public void resize(size_t size) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    66
    return data_.resize(size);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    67
    }*/
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    68
    /** Immutable add */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    69
    public static ByteArray plus(ByteArray a, ByteArray b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    70
        ByteArray x = new ByteArray(a.getData());
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    71
        x.append(b);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    72
        return x;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    73
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    74
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    75
    /** Immutable add */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    76
    /*public ByteArray plus(ByteArray a, char b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    77
        ByteArray x = new ByteArray(a.getData());
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    78
        x.append(b);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    79
        return x;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    80
    }*/
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    81
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    82
    /** Mutable add */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    83
    public ByteArray append(ByteArray b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    84
        append(b.getData());
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    85
        return this;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    86
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    87
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    88
    /** Mutable add */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    89
    private ByteArray append(byte[] b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    90
        int newLength = data_.length + b.length;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    91
        byte[] newData = new byte[newLength];
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    92
        for (int i = 0; i < data_.length; i++) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    93
            newData[i] = data_[i];
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    94
        }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    95
        for (int i = 0; i < b.length; i++) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    96
            newData[i + data_.length] = b[i];
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    97
        }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    98
        data_ = newData;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
    99
        return this;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   100
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   101
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   102
    /** Mutable add */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   103
    public ByteArray append(byte b) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   104
        byte[] bytes = {b};
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   105
        append(bytes);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   106
        return this;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   107
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   108
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   109
    /** mutable add */
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   110
    public ByteArray append(String s) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   111
        byte[] bytes;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   112
        try {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   113
            bytes = s.getBytes("UTF-8");
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   114
        } catch (UnsupportedEncodingException ex) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   115
            throw new IllegalStateException("JVM has no 'UTF-8' encoding");
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   116
        }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   117
        append(bytes);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   118
        return this;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   119
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   120
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   121
    @Override
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   122
    public int hashCode() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   123
        int hash = 3;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   124
        hash = 97 * hash + (this.data_ != null ? this.data_.hashCode() : 0);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   125
        return hash;
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   126
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   127
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   128
    @Override
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   129
    public boolean equals(Object other) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   130
        return other instanceof ByteArray && toString().equals(other.toString());
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   131
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   132
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   133
    /*public char charAt(int i) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   134
        return data_.charAt(i);
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   135
    }*/
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   136
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   137
    /*public const_iterator begin() const {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   138
    return data_.begin();
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   139
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   140
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   141
    public const_iterator end() const {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   142
    return data_.end();
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   143
    }*/
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   144
    @Override
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   145
    public String toString() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   146
        try {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   147
            return new String(data_, "UTF-8");
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   148
        } catch (UnsupportedEncodingException ex) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   149
            throw new IllegalStateException("JVM has no 'UTF-8' encoding");
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   150
        }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   151
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   152
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   153
    public void readFromFile(String file) {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   154
        //FIXME: port
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   155
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   156
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   157
    public void clear() {
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   158
        data_ = new byte[]{};
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   159
    }
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   160
    private byte[] data_ = {};
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   161
63669480c941 Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff changeset
   162
}