skipcheck

TM1 client · Docs · Queries

Utf8Repair

import io.skipcheck.tm1.client.odata.Utf8Repair;

Makes a response's bytes valid UTF-8 before they're read as JSON: each byte that isn't part of a character becomes U+FFFD, the replacement character, and everything else is kept as it is.

TM1 (11.8) writes some values into its JSON as the bytes it holds rather than as text. The transaction log is where it shows: setting a user's password logs the change of the PASSWORD cell of ClientProperties} with the password's hash as its new value, bytes that aren't UTF-8. A JSON parser refuses the whole response for them, so one such entry would make the log unreadable.

An instance repairs one body given in pieces, keeping a character split across two pieces whole; whole repairs a body held in one array. Bytes that are all ASCII, as most of TM1's are, are returned as given, without copying.

Members

Utf8Repair constructorA repairer for one body.
whole staticRepairs a whole body.
feedRepairs the next piece of the body.
endEnds the body.

Utf8Repair

constructor
Utf8Repair()

A repairer for one body.

whole

static
static byte[] whole(byte[] bytes)

Repairs a whole body.

Parameters

bytes
the body

Returns

the body as valid UTF-8; the same array if it was all ASCII

feed

byte[] feed(byte[] bytes)

Repairs the next piece of the body.

Parameters

bytes
the piece

Returns

what can be read so far, as valid UTF-8: the piece without the start of a character it ends in the middle of, which comes with the next piece

end

byte[] end()

Ends the body.

Returns

what's left: a replacement character for a character the body ended in the middle of, or nothing

Also in the Javadoc.