I have a huge string that I need to cache somewhere and since I cannot write to file my only option is to store this on the data base as text, more specifically, in the clob I have I'm storing a JSON file where I'm placing the compressed string under a certain key of that JSON object.

I'm compressing the strings but somewhere across the string manipulation something happens that doesn't allow me to decompress the data, so I'm wondering if I should encode the data to base 64 but that will lose compression.

What could I do to ensure I can store the compressed string in the database so I can later fetch it?

I cannot change the database, so I'm stuck with that CLOB field

These are my compression functions:

```
public static String compress(String text) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        OutputStream out = new DeflaterOutputStream(baos);
        out.write(text.getBytes("UTF-8"));
        out.close();
    } catch (IOException e) {
        //ooops
    }
    return baos.toString();
}

public static String decompress(String bytes) {
    InputStream in = new InflaterInputStream(new ByteArrayInputStream(bytes.getBytes()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        byte[] buffer = new byte[8192];
        int len;
        while ((len = in.read(buffer)) > 0)
            baos.write(buffer, 0, len);
        return new String(baos.toByteArray(), "UTF-8");
    } catch (IOException e) {
        //ooops
    }
}

```