Example usage for java.nio ByteBuffer getInt

List of usage examples for java.nio ByteBuffer getInt

Introduction

In this page you can find the example usage for java.nio ByteBuffer getInt.

Prototype

public abstract int getInt();

Source Link

Document

Returns the int at the current position and increases the position by 4.

Usage

From source file:com.github.ambry.utils.UtilsTest.java

@Test
public void testSerializeString() {
    String randomString = getRandomString(10);
    ByteBuffer outputBuffer = ByteBuffer.allocate(4 + randomString.getBytes().length);
    Utils.serializeString(outputBuffer, randomString, StandardCharsets.US_ASCII);
    outputBuffer.flip();//from   w  w  w.j  a  v  a  2  s  .c o m
    int length = outputBuffer.getInt();
    assertEquals("Input and output string lengths don't match", randomString.getBytes().length, length);
    byte[] output = new byte[length];
    outputBuffer.get(output);
    assertFalse("Output buffer shouldn't have any remaining, but has " + outputBuffer.remaining() + " bytes",
            outputBuffer.hasRemaining());
    String outputString = new String(output);
    assertEquals("Input and output strings don't match", randomString, outputString);

    randomString = getRandomString(10) + "";
    outputBuffer = ByteBuffer.allocate(4 + randomString.getBytes().length);
    Utils.serializeString(outputBuffer, randomString, StandardCharsets.US_ASCII);
    outputBuffer.flip();
    length = outputBuffer.getInt();
    assertEquals("Input and output string lengths don't match ", (randomString.getBytes().length - 1), length);
    output = new byte[length];
    outputBuffer.get(output);
    assertFalse("Output buffer shouldn't have any remaining, but has " + outputBuffer.remaining() + " bytes",
            outputBuffer.hasRemaining());
    outputString = new String(output);
    randomString = randomString.substring(0, randomString.length() - 1) + "?";
    assertEquals("Input and output strings don't match", randomString, outputString);

    randomString = "";
    outputBuffer = ByteBuffer.allocate(4);
    Utils.serializeString(outputBuffer, randomString, StandardCharsets.US_ASCII);
    outputBuffer.flip();
    length = outputBuffer.getInt();
    assertEquals("Input and output string lengths don't match", 0, length);
    output = new byte[length];
    outputBuffer.get(output);
    assertFalse("Output buffer shouldn't have any remaining, but has " + outputBuffer.remaining() + " bytes",
            outputBuffer.hasRemaining());
    outputString = new String(output);
    assertEquals("Output string \"" + outputString + "\" expected to be empty", outputString, "");

    randomString = getRandomString(10);
    outputBuffer = ByteBuffer.allocate(4 + randomString.getBytes().length - 1);
    try {
        Utils.serializeString(outputBuffer, randomString, StandardCharsets.US_ASCII);
        Assert.fail("Serialization should have failed due to insufficient space");
    } catch (RuntimeException e) {
    }
}

From source file:com.mellanox.jxio.EventQueueHandler.java

private boolean handleEvent(ByteBuffer eventQueue) {

    Eventable eventable;/*  w ww  .j  av  a 2s .  com*/
    int eventType = eventQueue.getInt();
    long id = eventQueue.getLong();
    boolean userNotified = false;
    switch (eventType) {

    case 0: // session error event
    {
        int errorType = eventQueue.getInt();
        int reason = eventQueue.getInt();
        EventSession evSes = new EventSession(eventType, id, errorType, reason);
        synchronized (eventables) {
            eventable = eventables.get(id);
        }
        if (eventable == null) {
            LOG.warn(
                    this.toLogString() + "eventable with id " + Long.toHexString(id) + " was not found in map");
            break;
        }
        userNotified = eventable.onEvent(evSes);
    }
        break;

    case 1: // msg error server
    {

        // msg was added to msgsPendingNewRequest after sendResponce. the real lookup of the Msg is done on C
        // side. msgsPendingNewRequest is used for look up of the java object based on the id
        Msg msg = this.msgsPendingNewRequest.remove(id);
        final long session_id = eventQueue.getLong();
        final int reason = eventQueue.getInt();
        eventable = eventables.get(session_id);
        if (eventable == null) {
            LOG.warn(this.toLogString() + "eventable with id " + Long.toHexString(session_id)
                    + " was not found in map");
            break;
        }
        EventMsgError evMsgErr = new EventMsgError(eventType, id, msg, reason);
        userNotified = eventable.onEvent(evMsgErr);
    }
        break;

    case 2: // msg error client
    {
        Msg msg = msgsPendingReply.remove(id);
        final int reason = eventQueue.getInt();
        EventMsgError evMsgErr = new EventMsgError(eventType, id, msg, reason);
        eventable = msg.getClientSession();
        userNotified = eventable.onEvent(evMsgErr);

    }
        break;

    case 3: // session established
    {
        EventSessionEstablished evSesEstab = new EventSessionEstablished(eventType, id);
        eventable = eventables.get(id);
        if (eventable == null) {
            LOG.warn(
                    this.toLogString() + "eventable with id " + Long.toHexString(id) + " was not found in map");
            break;
        }
        userNotified = eventable.onEvent(evSesEstab);
    }
        break;

    case 4: // on request (server side)
    {
        Msg msg = this.msgsPendingNewRequest.remove(id);
        msg.resetPositions();
        final int msg_in_size = eventQueue.getInt();
        msg.getIn().limit(msg_in_size);
        int msg_out_size = eventQueue.getInt();
        if (msg_out_size > msg.getOut().capacity())
            msg_out_size = msg.getOut().capacity();
        msg.getOut().limit(msg_out_size);
        final long session_id = eventQueue.getLong();
        if (LOG.isTraceEnabled()) {
            LOG.trace(this.toLogString() + "session refToCObject " + Long.toHexString(session_id));
        }
        eventable = eventables.get(session_id);
        if (eventable == null) {
            LOG.warn(this.toLogString() + "eventable with id " + Long.toHexString(session_id)
                    + " was not found in map");
            break;
        }
        EventNewMsg evMsg = new EventNewMsg(eventType, id, msg);
        userNotified = eventable.onEvent(evMsg);
    }
        break;

    case 5: // on response (client side)
    {
        Msg msg = msgsPendingReply.remove(id);
        final int msg_size = eventQueue.getInt();
        msg.getIn().limit(msg_size);
        if (LOG.isTraceEnabled()) {
            LOG.trace(this.toLogString() + "got msg " + msg);
        }
        EventNewMsg evMsg = new EventNewMsg(eventType, id, msg);
        eventable = msg.getClientSession();
        if (LOG.isTraceEnabled()) {
            LOG.trace(this.toLogString() + "eventable is " + eventable);
        }
        userNotified = eventable.onEvent(evMsg);
    }
        break;

    case 6: // on new session
    {
        long ptrSes = eventQueue.getLong();
        String uri = readString(eventQueue);
        String srcIP = readString(eventQueue);

        synchronized (eventables) {
            eventable = eventables.get(id);
        }
        if (eventable == null) {
            LOG.warn(
                    this.toLogString() + "eventable with id " + Long.toHexString(id) + " was not found in map");
            break;
        }
        EventNewSession evNewSes = new EventNewSession(eventType, id, ptrSes, uri, srcIP);
        userNotified = eventable.onEvent(evNewSes);
    }
        break;

    case 8: // on fd ready
    {
        /*
         * int fd = eventQueue.getInt(); int events = eventQueue.getInt();
         */
        LOG.error(this.toLogString() + "received FD Ready event - not handled");
    }
        break;

    default:
        LOG.error(this.toLogString() + "received an unknown event " + eventType);
        // TODO: throw exception
    }
    return userNotified;
}

From source file:com.yobidrive.diskmap.needles.Needle.java

public boolean getNeedleHeaderFromBuffer(ByteBuffer input) throws Exception {
    try {// ww w .  j  a v  a 2 s  . c  o  m
        // Reinit needle
        keyBytes = null;
        version = null;
        flags = 0x00;
        size = 0;
        data = null;
        previousNeedle = null; // Chaining
        readBytes = 0;
        // Processes reading
        input.rewind();
        int startPosition = input.position();
        int magic = input.getInt();
        if (magic == MAGICSTART_BADENDIAN) {
            if (input.order().equals(ByteOrder.BIG_ENDIAN))
                input.order(ByteOrder.LITTLE_ENDIAN);
            else
                input.order(ByteOrder.BIG_ENDIAN);
        } else if (magic != MAGICSTART) {
            logger.error("Buffer not starting with needle");
            return false;
        }
        needleNumber = input.getLong();
        flags = input.get();
        int keyLen = input.getInt();
        if (keyLen > 2028) {
            logger.error("Crazy needle key len");
            return false;
        }
        keyBytes = new byte[keyLen];
        input.get(keyBytes);
        int versionLen = input.getInt();
        if (versionLen > 1024 * 16) {
            logger.error("Crazy needle version len");
            return false;
        }
        if (versionLen == 0)
            version = null;
        else {
            byte[] versionBytes = new byte[versionLen];
            input.get(versionBytes);
            version = new VectorClock(versionBytes);
        }
        int previousLogNumber = input.getInt(); // Chaining
        long previousNeedleOffset = input.getLong(); // Chaining
        if (previousLogNumber != -1 && previousNeedleOffset != -1L) {
            previousNeedle = new NeedlePointer();
            previousNeedle.setNeedleFileNumber(previousLogNumber);
            previousNeedle.setNeedleOffset(previousNeedleOffset);
        }
        originalFileNumber = input.getInt(); // Original needle location (for cleaning)
        originalSize = input.getInt(); // Original needle size (for cleaning)
        size = input.getInt();

        readBytes = input.position() - startPosition;
        input.rewind();
        // input.mark() ;
        return true;
    } catch (BufferUnderflowException bue) {
        return false;
    }
}

From source file:org.bimserver.collada.ColladaSerializer.java

private List<String> intBufferToStringList(ByteBuffer buffer, Format formatter) {
    List<Integer> list = new ArrayList<Integer>();
    while (buffer.hasRemaining())
        list.add(new Integer(buffer.getInt()));
    // Get the data as a list of String objects.
    return listToStringList(list, formatter);
}

From source file:guru.benson.pinch.Pinch.java

/**
 * Parses the ZIP central directory from a byte buffer.
 *
 * @param data/*from  ww w .ja  v  a  2  s  .c  om*/
 *     The byte buffer to be parsed.
 *
 * @return {@code true} if central directory was parsed, otherwise {@code false}
 */
private boolean parseEndOfCentralDirectory(byte[] data) {

    byte[] zipEndSignature = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN)
            .putInt((int) ZipConstants.ENDSIG).array();

    // find start of ZIP archive signature.
    int index = KMPMatch.indexOf(data, zipEndSignature);

    if (index < 0) {
        return false;
    }

    // wrap our head around a part of the buffer starting with index.
    ByteBuffer buf = ByteBuffer.wrap(data, index, data.length - index);
    buf.order(ByteOrder.LITTLE_ENDIAN);

    /*
     * For ZIP header descriptions, see
     * http://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers
     */

    // skip signature
    buf.getInt();
    // skip numberOfThisDisk
    buf.getShort();
    // skip diskWhereCentralDirectoryStarts =
    buf.getShort();
    // skip numberOfCentralDirectoriesOnThisDisk
    buf.getShort();

    entriesCount = buf.getShort();
    centralDirectorySize = buf.getInt();
    centralDirectoryOffset = buf.getInt();
    zipFileCommentLength = buf.getShort();

    return true;
}

From source file:org.zuinnote.hadoop.bitcoin.format.BitcoinBlockReader.java

/**
* Parses the Bitcoin transactions in a byte buffer. 
*
* @param rawByteBuffer ByteBuffer from which the transactions have to be parsed
* @param noOfTransactions Number of expected transactions
*
* @return Array of transactions/*from w w w  .j a  va2s  .c  o m*/
*
*
*/

public List<BitcoinTransaction> parseTransactions(ByteBuffer rawByteBuffer, long noOfTransactions) {
    ArrayList<BitcoinTransaction> resultTransactions = new ArrayList<BitcoinTransaction>(
            new Long(noOfTransactions).intValue());
    // read all transactions from ByteBuffer
    for (int k = 0; k < noOfTransactions; k++) {
        // read version
        int currentVersion = rawByteBuffer.getInt();
        // read inCounter
        byte[] currentInCounterVarInt = BitcoinUtil.convertVarIntByteBufferToByteArray(rawByteBuffer);
        long currentNoOfInputs = BitcoinUtil.getVarInt(currentInCounterVarInt);
        // read inputs
        ArrayList<BitcoinTransactionInput> currentTransactionInput = new ArrayList<BitcoinTransactionInput>(
                new Long(currentNoOfInputs).intValue());

        for (int i = 0; i < currentNoOfInputs; i++) {
            // read previous Hash of Transaction
            byte[] currentTransactionInputPrevTransactionHash = new byte[32];
            rawByteBuffer.get(currentTransactionInputPrevTransactionHash, 0, 32);
            // read previousTxOutIndex
            long currentTransactionInputPrevTxOutIdx = BitcoinUtil
                    .convertSignedIntToUnsigned(rawByteBuffer.getInt());
            // read InScript length (Potential Internal Exceed Java Type)
            byte[] currentTransactionTxInScriptLengthVarInt = BitcoinUtil
                    .convertVarIntByteBufferToByteArray(rawByteBuffer);
            long currentTransactionTxInScriptSize = BitcoinUtil
                    .getVarInt(currentTransactionTxInScriptLengthVarInt);
            // read inScript
            int currentTransactionTxInScriptSizeInt = new Long(currentTransactionTxInScriptSize).intValue();
            byte[] currentTransactionInScript = new byte[currentTransactionTxInScriptSizeInt];
            rawByteBuffer.get(currentTransactionInScript, 0, currentTransactionTxInScriptSizeInt);
            // read sequence no
            long currentTransactionInputSeqNo = BitcoinUtil.convertSignedIntToUnsigned(rawByteBuffer.getInt());
            // add input
            currentTransactionInput.add(new BitcoinTransactionInput(currentTransactionInputPrevTransactionHash,
                    currentTransactionInputPrevTxOutIdx, currentTransactionTxInScriptLengthVarInt,
                    currentTransactionInScript, currentTransactionInputSeqNo));
        }
        // read outCounter
        byte[] currentOutCounterVarInt = BitcoinUtil.convertVarIntByteBufferToByteArray(rawByteBuffer);
        long currentNoOfOutput = BitcoinUtil.getVarInt(currentOutCounterVarInt);
        // read outputs
        ArrayList<BitcoinTransactionOutput> currentTransactionOutput = new ArrayList<BitcoinTransactionOutput>(
                new Long(currentNoOfOutput).intValue());
        for (int i = 0; i < currentNoOfOutput; i++) {
            // read value
            long currentTransactionOutputValue = rawByteBuffer.getLong();
            // read outScript length (Potential Internal Exceed Java Type)
            byte[] currentTransactionTxOutScriptLengthVarInt = BitcoinUtil
                    .convertVarIntByteBufferToByteArray(rawByteBuffer);
            long currentTransactionTxOutScriptSize = BitcoinUtil
                    .getVarInt(currentTransactionTxOutScriptLengthVarInt);
            int currentTransactionTxOutScriptSizeInt = new Long(currentTransactionTxOutScriptSize).intValue();
            // read outScript
            byte[] currentTransactionOutScript = new byte[currentTransactionTxOutScriptSizeInt];
            rawByteBuffer.get(currentTransactionOutScript, 0, currentTransactionTxOutScriptSizeInt);
            currentTransactionOutput.add(new BitcoinTransactionOutput(currentTransactionOutputValue,
                    currentTransactionTxOutScriptLengthVarInt, currentTransactionOutScript));
        }
        // lock_time
        int currentTransactionLockTime = rawByteBuffer.getInt();
        // add transaction
        resultTransactions
                .add(new BitcoinTransaction(currentVersion, currentInCounterVarInt, currentTransactionInput,
                        currentOutCounterVarInt, currentTransactionOutput, currentTransactionLockTime));
    }
    return resultTransactions;
}

From source file:edu.umass.cs.gigapaxos.paxospackets.PaxosPacket.java

protected PaxosPacket(ByteBuffer bbuf) throws UnsupportedEncodingException, UnknownHostException {
    super(PaxosPacketType.PAXOS_PACKET);

    bbuf.getInt(); // packet type
    this.packetType = PaxosPacketType.getPaxosPacketType(bbuf.getInt());
    this.version = bbuf.getInt();
    byte paxosIDLength = bbuf.get();
    byte[] paxosIDBytes = new byte[paxosIDLength];
    bbuf.get(paxosIDBytes);//from w  ww .j  a v  a  2  s . c om
    this.paxosID = paxosIDBytes.length > 0 ? new String(paxosIDBytes, CHARSET) : null;
    int exactLength = (4 + 4 + 4 + 1 + paxosIDBytes.length);
    assert (bbuf.position() == exactLength);
}

From source file:org.apache.carbondata.core.util.CarbonUtil.java

/**
 * Below method will be used to get the surrogate key
 *
 * @param data   actual data/*from w ww  .ja  v  a  2 s  . c o  m*/
 * @param buffer byte buffer which will be used to convert the data to integer value
 * @return surrogate key
 */
public static int getSurrogateKey(byte[] data, ByteBuffer buffer) {
    int lenght = 4 - data.length;
    for (int i = 0; i < lenght; i++) {
        buffer.put((byte) 0);
    }
    buffer.put(data);
    buffer.rewind();
    int surrogate = buffer.getInt();
    buffer.clear();
    return surrogate;
}

From source file:com.vkassin.mtrade.Common.java

public static void login(final Context ctx) {

    // ctx = Common.app_ctx;
    Common.connected = false;//from w w  w . j a v a  2 s .  co  m

    if (inLogin)
        return;

    inLogin = true;

    if (Common.mainActivity != null)
        Common.mainActivity.handler.sendMessage(
                Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG));

    // while(true) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.login_dialog);
    dialog.setTitle(R.string.LoginDialogTitle);
    dialog.setCancelable(false);

    final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit);
    final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit);
    final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1);
    final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2);
    final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2);

    String nam = myaccount.get("name");
    Common.oldName = nam;

    if (nam != null) {

        nametxt.setText(nam);
        passtxt.requestFocus();
    }

    Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister);
    customDialog_Register.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle1);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.VISIBLE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.GONE);
        }

    });

    Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1);
    customDialog_Register1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            if (mailtxt.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

                return;
            }

            if (passtxt1.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            try {

                Socket sock = new Socket(ip_addr, port_register);

                JSONObject msg = new JSONObject();
                msg.put("objType", Common.MSG_REGISTER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("user", mailtxt.getText().toString());
                msg.put("passwd", passtxt1.getText().toString());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString()));

                byte[] array = msg.toString().getBytes();
                ByteBuffer buff = ByteBuffer.allocate(array.length + 4);
                buff.putInt(array.length);
                buff.put(array);
                sock.getOutputStream().write(buff.array());

                ByteBuffer buff1 = ByteBuffer.allocate(4);
                buff1.put(readMsg(sock.getInputStream(), 4));
                buff1.position(0);
                int pkgSize = buff1.getInt();
                // Log.i(TAG, "size = "+pkgSize);
                String s = new String(readMsg(sock.getInputStream(), pkgSize));

                sock.close();

                JSONObject jo = new JSONObject(s);

                Log.i(TAG, "register answer = " + jo);

                int t = jo.getInt("status");
                switch (t) {

                case 1:
                    Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast.show();

                    dialog.setTitle(R.string.LoginDialogTitle);
                    final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
                    layreg.setVisibility(View.GONE);
                    final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
                    laylog.setVisibility(View.VISIBLE);

                    nametxt.setText(mailtxt.getText());
                    break;

                case -2:
                    Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG);
                    toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast1.show();
                    break;

                default:
                    Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG);
                    toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast2.show();
                    break;

                }

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error in registration process!!", e);

                Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

            }

        }

    });

    Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg);
    customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.GONE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.VISIBLE);

        }

    });

    Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin);
    customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0);
            Common.isSSL = bu0.isChecked();

            inLogin = false;

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.LOGOUT);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("status", 1);
                mainActivity.writeJSONMsg(msg);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON logout object", e);
            }

            myaccount.put("name", nametxt.getText().toString());
            myaccount.put("password", passtxt.getText().toString());

            Log.i(TAG,
                    "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password"));

            dialog.dismiss();
            mainActivity.stop();
            // saveAccountDetails();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            loginFromDialog = true;
            //            mainActivity.refresh();

            Common.keypassword(ctx);
        }

    });

    dialog.show();
    // Common.confChanged = false;
    // }//while(true);

}

From source file:org.zuinnote.hadoop.bitcoin.format.BitcoinBlockReader.java

/**
* Read a block into a Java object of the class Bitcoin Block. This makes analysis very easy, but might be slower for some type of analytics where you are only interested in small parts of the block. In this case it is recommended to use {@link #readRawBlock}
*
* @return BitcoinBlock//from ww w  .  j a  v a 2s  .c  o m
* @throws java.io.IOException in case of errors reading from the InputStream
* @throws org.zuinnote.hadoop.bitcoin.format.exception.BitcoinBlockReadException in case of format errors of the Bitcoin Blockchain data
*/

public BitcoinBlock readBlock() throws BitcoinBlockReadException, IOException {
    ByteBuffer rawByteBuffer = readRawBlock();
    if (rawByteBuffer == null)
        return null;
    // start parsing
    // initialize byte arrays
    byte[] currentMagicNo = new byte[4];
    byte[] currentBits = new byte[4];
    byte[] currentHashMerkleRoot = new byte[32];
    byte[] currentHashPrevBlock = new byte[32];
    // magic no
    rawByteBuffer.get(currentMagicNo, 0, 4);
    // blocksize
    int currentBlockSize = rawByteBuffer.getInt();
    // version
    int currentVersion = rawByteBuffer.getInt();
    // hashPrevBlock
    rawByteBuffer.get(currentHashPrevBlock, 0, 32);
    // hashMerkleRoot
    rawByteBuffer.get(currentHashMerkleRoot, 0, 32);
    // time 
    int currentTime = rawByteBuffer.getInt();
    // bits/difficulty
    rawByteBuffer.get(currentBits, 0, 4);
    // nonce
    int currentNonce = rawByteBuffer.getInt();
    // read var int from transaction counter

    long currentTransactionCounter = BitcoinUtil.convertVarIntByteBufferToLong(rawByteBuffer);
    // parse transactions 
    List<BitcoinTransaction> allBlockTransactions = parseTransactions(rawByteBuffer, currentTransactionCounter);
    if (allBlockTransactions.size() != currentTransactionCounter)
        throw new BitcoinBlockReadException("Error: Number of Transactions (" + allBlockTransactions.size()
                + ") does not correspond to transaction counter in block (" + currentTransactionCounter + ")");
    BitcoinBlock result = new BitcoinBlock(currentMagicNo, currentBlockSize, currentVersion, currentTime,
            currentBits, currentNonce, currentTransactionCounter, currentHashPrevBlock, currentHashMerkleRoot,
            allBlockTransactions);
    return result;
}