Question

I know this may be a weird question to be asking, but I came across this method and is not too sure of it's purpose.

I been reading online for it's explanation, but did not find one that is easily understood.

What I need is not a code, but rather why should it be implemented.

The snippet code are as follow:

private PrintWriter out;
private static final String end = "067e6162-3b6f-4ae2-a171-2470b63dff00 ";  
//generated using the above method, UUID.randomUUID()

public static String getEnd() {
    return end;
}

private void sendOutputToClientFile(String str) {
    out.println(str);
    out.println();
    out.println(end);
}

The codes are found inside a server file, and is supposedly use to denote the end of message.

But what purpose does it serve here and why is it necessary?

P.S : I would prefer a layman's term of explanation...

Was it helpful?

Solution

The code writes the random string that is assumed (and with astronomic level of probability very likely to be true) unique, no other calls to UUID.randomUUID will probably ever produce it. Probably this string is checked at another end as the "end of stream" sequence.

Most likely the designer was not able to reserve any particular char sequence to mark the end of the data stream, and for some reason could not use the usual IO methods either. It is highly unlikely that such string will appear inside the stream as well for some reason just by chance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top