Fehler auf der Rückleitung erhalten und auch nicht sicher, ob die Überprüfung für die Größe richtig ist.Wie überprüfe ich Java für variable Größe?
private byte[] Get(String urlIn)
{
URL url = null;
String urlStr = urlIn;
if (urlIn!=null)
urlStr=urlIn;
try
{
url = new URL(urlStr);
} catch (MalformedURLException e)
{
e.printStackTrace();
return null;
}
HttpURLConnection urlConnection = null;
try
{
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
byte[] buf=new byte[10*1024];
int szRead = in.read(buf);
byte[] bufOut;
if (szRead==10*1024)
{
throw new AndroidRuntimeException("the returned data is bigger than 10*1024.. we don't handle it..");
}
else
{
if (szRead > 0) {
bufOut = Arrays.copyOf(buf, szRead);
}
}
return bufOut;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
finally
{
if (urlConnection!=null)
urlConnection.disconnect();
}
}
Der Teil:
if (szRead > 0) {
bufOut = Arrays.copyOf(buf, szRead);
}
Nicht sicher, ob dies der richtige Weg ist es in Java zu überprüfen und auch wenn dies zu tun, ich bin Fehler auf die Variable BUFOUT bekommen möglicherweise nicht in diese init werden Leitung:
return bufOut;
Sie, bevor Sie sie lokale Variable initialisieren sollte !! – Prashant