MCPcopy Create free account
hub / github.com/M66B/FairEmail / copyAndClose

Method copyAndClose

app/src/main/java/androidx/room/CursorUtil.java:47–81  ·  view source on GitHub ↗

Copies the given cursor into a in-memory cursor and then closes it. This is useful for iterating over a cursor multiple times without the cost of JNI while reading or IO while filling the window at the expense of memory consumption. @param c the cursor to copy. @return a new cursor containing t

(@NonNull Cursor c)

Source from the content-addressed store, hash-verified

45 * @return a new cursor containing the same data as the given cursor.
46 */
47 @NonNull
48 public static Cursor copyAndClose(@NonNull Cursor c) {
49 final MatrixCursor matrixCursor;
50 try {
51 matrixCursor = new MatrixCursor(c.getColumnNames(), c.getCount());
52 while (c.moveToNext()) {
53 final Object[] row = new Object[c.getColumnCount()];
54 for (int i = 0; i < c.getColumnCount(); i++) {
55 switch (c.getType(i)) {
56 case Cursor.FIELD_TYPE_NULL:
57 row[i] = null;
58 break;
59 case Cursor.FIELD_TYPE_INTEGER:
60 row[i] = c.getLong(i);
61 break;
62 case Cursor.FIELD_TYPE_FLOAT:
63 row[i] = c.getDouble(i);
64 break;
65 case Cursor.FIELD_TYPE_STRING:
66 row[i] = c.getString(i);
67 break;
68 case Cursor.FIELD_TYPE_BLOB:
69 row[i] = c.getBlob(i);
70 break;
71 default:
72 throw new IllegalStateException();
73 }
74 }
75 matrixCursor.addRow(row);
76 }
77 } finally {
78 c.close();
79 }
80 return matrixCursor;
81 }
82
83 /**
84 * Patches {@link Cursor#getColumnIndex(String)} to work around issues on older devices.

Callers 1

queryMethod · 0.95

Calls 10

getColumnNamesMethod · 0.80
moveToNextMethod · 0.80
getLongMethod · 0.80
getDoubleMethod · 0.80
getBlobMethod · 0.80
getCountMethod · 0.65
getColumnCountMethod · 0.45
getTypeMethod · 0.45
getStringMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected