如何将Writer转换为Byte数组

时间:2014-08-19 23:41:23

标签: java hibernate

我需要将blob内容写入数据库。我正在使用编写器Object。

那是:
 OutputStreamWriter writer = getMyWriter();

我需要知道如何将这个writer对象转换为字节数组。?

我需要这个字节数组,因为要创建blob我将字节数组传递给Hibernate实体。我已粘贴代码供参考:

   public void writeBolobSecuredContentToDb() throws Exception {
    OutputStreamWriter writer = getMyWriter();
    formattedContentToWriter(writer);

   // Writing to Database

     UserPersonal secureData = UserPersonal() 
     userPersonal.fromBytArray("How to convert my writer object to byte array?");
     writer.flush();
     writer.close();
 }

    public OutputStreamWriter getMyWriter() {   
     CipherOutputStream cos = null;
     try {
        cos = getEncrypttedCipherOutputStream();
        return new OutputStreamWriter(cos);
    } catch (Exception e) {
        throw new IllegalStateException("Could not create cipher outputstream.", e);
    }
}


}

//Hibernate entity
public class UserPersonal implements java.io.Serializable
public static Stock fromBytArray(byte[] content) {          
        fileContent.setContent(Hibernate.createBlob(content));
        return (fileContent);
    }

0 个答案:

没有答案