Code example for ByteArrayOutputStream

Methods: closetoByteArrayflush

0
 
    public static String objectToString(Object obj)
                                                   throws IllegalArgumentException { 
        String objRef64enc;
        try { 
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject(obj);
            oos.close();
            objRef64enc = Base64Coder.encodeLines(os.toByteArray());
            os.flush();
            os.close();
        } catch (Exception ex) {
            throw new IllegalArgumentException(
                                               "Not possible to convert object to String"); 
        } 
        return objRef64enc;
    } 
 
    // variables. 
Experience pair programming with AI  Get Codota for Java