Java tutorial
//package com.java2s; /** * Copyright (c) 2012 Todoroo Inc * * See the file "LICENSE" for the full license governing this code. */ public class Main { public static final String SEPARATOR_ESCAPE = "!PIPE!"; public static final String SERIALIZATION_SEPARATOR = "|"; /** add serialized helper */ private static void addSerialized(StringBuilder result, String key, Object value) { result.append(key.replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE)).append(SERIALIZATION_SEPARATOR); if (value instanceof Integer) { result.append('i').append(value); } else if (value instanceof Double) { result.append('d').append(value); } else if (value instanceof Long) { result.append('l').append(value); } else if (value instanceof String) { result.append('s').append(value.toString().replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE)); } else if (value instanceof Boolean) { result.append('b').append(value); } else { throw new UnsupportedOperationException(value.getClass().toString()); } result.append(SERIALIZATION_SEPARATOR); } }