@Override
    public String readString(String encoding, int length) throws IOException
    {
        Charset charset = Charset.forName(encoding);
        CharsetDecoder dec = charset.newDecoder();
        ByteBuffer bin = ByteBuffer.allocate(8);
        CharBuffer bout = CharBuffer.allocate(1);
        String ret = "";
        
        for (int i = 0; length == 0 || i < length; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                try { bin.put(file.readByte()); }
                catch (EOFException ex) { bin.put((byte)0); }
            }
            bin.rewind();
            
            CoderResult res = dec.decode(bin, bout, false);
            if (res == CoderResult.UNDERFLOW)
                break;
            else if (res != CoderResult.OVERFLOW)
                throw new IOException("Error while reading string: " + res);
            
            skip(-bin.remaining());
            
            char ch = bout.get(0);
            if (ch == '\0') break;
            
            bin.clear();
            bout.clear();
            ret += ch;
        }
        
        return ret;
    }