次のスキーマを持つmysqlデータベースがあります
(int id, int sys_id, BLOB data)
同じ sys_id に対して複数のデータが存在する可能性があります。つまり、(1,1, blobdata1)、(2,1, blobdata2) などは有効なエントリです。ブロブ データは圧縮されたオーディオです。特定の sys_id のすべての行が結合されると、有効な圧縮オーディオ データが生成されます。
このブロブ データを Android デバイスに送信したいと考えています。次の php コードを使用してデータを送信しようとしましたが、クライアント側で期待どおりに受信されません。
$conn = mysql_connect("localhost","root","");
mysql_select_db("mydb", $conn);
global $blobId;
$blobId = $_GET['id'];
$result = mysql_query("SELECT data FROM table WHERE sys_id=$blobId");
if( mysql_num_rows($result) == 0 )
die("No rows returned");
while($row = mysql_fetch_array($result) ) {
// is this correct way of concatenating binary data
$temp .= $row['data'];
}
// PROBLEM: what should be sent
echo $temp;
すべての行をクライアント側で受信でき、そこでローカルに連結または操作できるかどうかは気にしません。
クライアント側では、次のことを行います。
// connect to the server
public void connect(URL url)
{
HttpURLConnection urlConnection = null;
try {
urlConnection = (HttpURLConnection)url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
result = readStream(in);
//problem, how should I now parse the resultant string
decompress(result.getBytes()); // result.getBytes() returns null currently
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
// for reading the incoming stream
public static String readStream(InputStream in) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader r = new BufferedReader(new InputStreamReader(in),1000);
for (String line = r.readLine(); line != null; line =r.readLine()){
sb.append(line);
}
in.close();
return sb.toString();
}
// definition for decompression utility
public short[] decompress(byte[] codBytes);