@@ -10,34 +10,50 @@ object CursorToVideoGsonConverter {
10
10
11
11
fun getVideoGson (cursor : Cursor ): VideoGson {
12
12
Log .i(TAG , " getVideoGson" )
13
-
14
13
Log .i(TAG , " Arrays.toString(cursor.getColumnNames()): "
15
14
+ cursor.columnNames.contentToString())
16
-
15
+ if (cursor.isBeforeFirst && ! cursor.moveToFirst()) {
16
+ throw IllegalArgumentException (" Cursor must be positioned on a valid row" )
17
+ }
17
18
val columnId = cursor.getColumnIndex(" id" )
19
+ if (columnId == - 1 ) {
20
+ throw IllegalArgumentException (" Column 'id' not found in cursor" )
21
+ }
18
22
val id = cursor.getLong(columnId)
19
23
Log .i(TAG , " id: $id " )
20
24
21
25
val columnRevisionNumber = cursor.getColumnIndex(" revisionNumber" )
26
+ if (columnRevisionNumber == - 1 ) {
27
+ throw IllegalArgumentException (" Column 'revisionNumber' not found in cursor" )
28
+ }
22
29
val revisionNumber = cursor.getInt(columnRevisionNumber)
23
30
Log .i(TAG , " revisionNumber: $revisionNumber " )
24
31
25
32
val columnTitle = cursor.getColumnIndex(" title" )
33
+ if (columnTitle == - 1 ) {
34
+ throw IllegalArgumentException (" Column 'title' not found in cursor" )
35
+ }
26
36
val title = cursor.getString(columnTitle)
27
37
Log .i(TAG , " title: \" $title \" " )
28
38
29
39
val columnVideoFormat = cursor.getColumnIndex(" videoFormat" )
40
+ if (columnVideoFormat == - 1 ) {
41
+ throw IllegalArgumentException (" Column 'videoFormat' not found in cursor" )
42
+ }
30
43
val videoFormatAsString = cursor.getString(columnVideoFormat)
31
44
Log .i(TAG , " videoFormatAsString: $videoFormatAsString " )
32
- val videoFormat = VideoFormat .valueOf(videoFormatAsString)
45
+ val videoFormat = try {
46
+ VideoFormat .valueOf(videoFormatAsString)
47
+ } catch (e: IllegalArgumentException ) {
48
+ Log .e(TAG , " Invalid video format: $videoFormatAsString " , e)
49
+ throw IllegalArgumentException (" Invalid video format: $videoFormatAsString " , e)
50
+ }
33
51
Log .i(TAG , " videoFormat: $videoFormat " )
34
-
35
52
val video = VideoGson ()
36
53
video.id = id
37
54
video.revisionNumber = revisionNumber
38
55
video.title = title
39
56
video.videoFormat = videoFormat
40
-
41
57
return video
42
58
}
43
59
}
0 commit comments