@@ -32,8 +32,10 @@ import android.net.Uri
32
32
import android.os.Build
33
33
import android.os.Environment
34
34
import android.provider.MediaStore
35
+ import android.util.Log
35
36
import com.esotericsoftware.kryo.Kryo
36
37
import com.esotericsoftware.kryo.io.Input
38
+ import com.esotericsoftware.kryo.io.KryoBufferUnderflowException
37
39
import com.esotericsoftware.kryo.io.Output
38
40
import org.catrobat.paintroid.colorpicker.ColorHistory
39
41
import org.catrobat.paintroid.command.Command
@@ -229,24 +231,26 @@ open class CommandSerializer(private val activityContext: Context, private val c
229
231
fun readFromInternalMemory (stream : FileInputStream ): WorkspaceReturnValue {
230
232
var commandModel: CommandManagerModel ? = null
231
233
var colorHistory: ColorHistory ? = null
232
-
233
- Input (stream).use { input ->
234
- if (! input.readString().equals(MAGIC_VALUE )) {
235
- throw NotCatrobatImageException (" Magic Value doesn't exist." )
236
- }
237
- val imageVersion = input.readInt()
238
- if (CURRENT_IMAGE_VERSION != imageVersion) {
239
- setRegisterMapVersion(imageVersion)
240
- registerClasses()
241
- }
242
- commandModel = kryo.readObject(input, CommandManagerModel ::class .java)
243
- if (input.available() != 0 ) {
244
- colorHistory = kryo.readObject(input, ColorHistory ::class .java)
234
+ try {
235
+ Input (stream).use { input ->
236
+ if (! input.readString().equals(MAGIC_VALUE )) {
237
+ throw NotCatrobatImageException (" Magic Value doesn't exist." )
238
+ }
239
+ val imageVersion = input.readInt()
240
+ if (CURRENT_IMAGE_VERSION != imageVersion) {
241
+ setRegisterMapVersion(imageVersion)
242
+ registerClasses()
243
+ }
244
+ commandModel = kryo.readObject(input, CommandManagerModel ::class .java)
245
+ if (input.available() != 0 ) {
246
+ colorHistory = kryo.readObject(input, ColorHistory ::class .java)
247
+ }
245
248
}
249
+ commandModel?.commands?.reverse()
250
+ } catch (e: KryoBufferUnderflowException ) {
251
+ Log .e(" readFromInternalMemory" , " Buffer underflow: ${e.message} " , e)
252
+ return WorkspaceReturnValue (null , null )
246
253
}
247
-
248
- commandModel?.commands?.reverse()
249
-
250
254
return WorkspaceReturnValue (commandModel, colorHistory)
251
255
}
252
256
0 commit comments