Java DataInputStream to Object deserializeString(DataInputStream din)

Here you can find the source of deserializeString(DataInputStream din)

Description

deserialize String

License

Open Source License

Declaration

public static String deserializeString(DataInputStream din) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    private static String tagNull = "Null";
    private static String tagString = "String";

    public static String deserializeString(DataInputStream din) throws IOException {
        String str;/* w w w. j a  v a  2s. c  o m*/
        if (deserializeHeaderString(tagString, din))
            str = din.readUTF();
        else
            str = null;
        deserializeTrailerString(tagString, din);
        return str;
    }

    private static boolean deserializeHeaderString(String str, DataInputStream din) throws IOException {
        String s2 = din.readUTF();
        if (s2.equals("[" + tagNull))
            return false;
        if (!s2.equals("[" + str))
            throw new IOException("bogus serialization header");
        return true;
    }

    private static void deserializeTrailerString(String str, DataInputStream din) throws IOException {
        String s2 = din.readUTF();
        // if ( ! s2.equals( str + "]" ) )
        //     throw new IOException( "bogus serialization trailer" );
        if (!s2.equals("]"))
            throw new IOException("bogus serialization trailer");
    }
}

Related

  1. deserialiseByteArray(DataInputStream is, int max_length)
  2. deserialiseByteArrayArray(DataInputStream is, int max_length)
  3. deserialiseLength(DataInputStream is, int max_length)
  4. deserializeInt(DataInputStream din)
  5. deserializeIntArray(DataInputStream in)
  6. deserializeTrailerString(String str, DataInputStream din)