このコードスニペットは、contentproviderを使用してPipeDataWriterを実装している最新のAndroidメモ帳チュートリアルリンクで見つかりました。
インターフェイスには、次のように実装されたメソッドwriteDataToPipeがあります。
@Override
public void writeDataToPipe(ParcelFileDescriptor output, Uri uri, String mimeType, Bundle opts, Cursor c) {
// We currently only support conversion-to-text from a single note entry,
// so no need for cursor data type checking here.
FileOutputStream fout = new FileOutputStream(output.getFileDescriptor());
PrintWriter pw = null;
try {
pw = new PrintWriter(new OutputStreamWriter(fout, "UTF-8"));
pw.println(c.getString(READ_NOTE_TITLE_INDEX));
pw.println("");
pw.println(c.getString(READ_NOTE_NOTE_INDEX));
} catch (UnsupportedEncodingException e) {
Log.w(TAG, "Ooops", e);
} finally {
c.close();
if (pw != null) {
pw.flush();
}
try {
fout.close();
} catch (IOException e) {
}
}
}
私の疑問は、なぜ彼らがPipeDataWriterを具体的に使用しているのかということです。
それはある種のデザインパターンですか?
私はそれが使用された他の情報源を見つけませんでした。なぜそうなのか?