Java Object Serialize and Deserialize deserializeFromString(String obj)

Here you can find the source of deserializeFromString(String obj)

Description

deserialize From String

License

Open Source License

Declaration

public static Object deserializeFromString(String obj) throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
/*/*  www .jav a 2 s.  c  o m*/
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

import java.util.StringTokenizer;

public class Main {
    public static Object deserializeFromString(String obj) throws IOException, ClassNotFoundException {
        byte[] b = stringToBytes(obj);
        ByteArrayInputStream bytes = new ByteArrayInputStream(b);
        ObjectInputStream stream = new ObjectInputStream(bytes);
        return stream.readObject();
    }

    private static byte[] stringToBytes(String s) {
        StringTokenizer tokenizer = new StringTokenizer(s);
        byte[] result = new byte[tokenizer.countTokens()];

        for (int i = 0; i < result.length; i++) {
            result[i] = Byte.parseByte(tokenizer.nextToken());
        }

        return result;
    }
}

Related

  1. deserialize(String serializedObject)
  2. deserialize(String str)
  3. deSerialize(String str)
  4. deserializeAndCheckObject(final byte[] object, final Class type)
  5. deserialized(final byte[] data)
  6. deserializeGZip(byte[] buf, T obj)
  7. deserializeJdk(byte[] bytes)
  8. deSerializeObj(byte[] array)
  9. deSerializeObject(byte[] base64SerializedObject)