cassandra row fetch 给出垃圾字符

cassandra row fetch gives junk characters

正在学习 Cassandra 并编写了一个可以从数据库中读取文件的 restclient。

下面是我从数据库中检索数据的代码。

        ResultSet rs = getFile(fileName);
        Row row=rs.one();

        ByteBuffer filecontent =row.getBytes("file_content");
        byte[] data = new byte[filecontent.remaining()];
        ByteBuffer bb = filecontent.get(data);

        String filelocation = row.getString("file_location");
        String filename = row.getString("filename");

        ByteArrayInputStream filecontentfromDB= new ByteArrayInputStream(bb.array());
        File file=writeToFile(filecontentfromDB,fileName);

        if (rs == null) {
            return null;
        }
        return file;

当我查看返回的文件时,我发现开头有一些垃圾字符,后面是我的文件内容。

请帮我删除垃圾数据

Yipee,已找到解决方案,应替换以下行

String filelocation = row.getString("file_location");
        String filename = row.getString("filename");

        ByteArrayInputStream filecontentfromDB= new ByteArrayInputStream(bb.array());

String filelocation = row.getString("file_location");
        String filename = row.getString("filename");
String bb = new String(filecontent.array(), filecontent.arrayOffset() + filecontent.position(), filecontent.remaining());
        ByteArrayInputStream filecontentfromDB= new ByteArrayInputStream(bb.getBytes());

有效。