Revision 1d643a0e
Added by Leszek Koltunski almost 3 years ago
src/main/java/org/distorted/network/RubikNetwork.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.network; |
21 | 21 |
|
22 |
import java.io.BufferedReader; |
|
22 | 23 |
import java.io.InputStream; |
24 |
import java.io.InputStreamReader; |
|
23 | 25 |
import java.net.HttpURLConnection; |
24 | 26 |
import java.net.URL; |
25 | 27 |
import java.net.UnknownHostException; |
... | ... | |
401 | 403 |
conn.connect(); |
402 | 404 |
conn.getOutputStream().flush(); |
403 | 405 |
|
404 |
try( InputStream is = conn.getInputStream() ) |
|
405 |
{ |
|
406 |
int ch; |
|
407 |
StringBuilder sb = new StringBuilder(); |
|
408 |
while( ( ch = is.read() ) != -1 ) |
|
409 |
{ |
|
410 |
sb.append( (char)ch ); |
|
411 |
} |
|
412 |
mScores = sb.toString(); |
|
413 |
} |
|
414 |
catch( final Exception e) |
|
406 |
InputStream is = conn.getInputStream(); |
|
407 |
BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
|
408 |
StringBuilder total = new StringBuilder(); |
|
409 |
|
|
410 |
for (String line; (line = r.readLine()) != null; ) |
|
415 | 411 |
{ |
416 |
if( mReceiver!=null ) mReceiver.message("Failed to get an answer from the High Scores server"); |
|
417 |
return false; |
|
412 |
total.append(line).append('\n'); |
|
418 | 413 |
} |
414 |
|
|
415 |
mScores = total.toString(); |
|
419 | 416 |
} |
420 | 417 |
catch( final UnknownHostException e ) |
421 | 418 |
{ |
Also available in: Unified diff
Highscores: corrections for handling names that are not written in the Latin character set.