@Test public void testWriteToFile() throws Exception { final SettingsProto.Settings message = new SettingsProto.Settings(); message.scrobbleEnabled = true; message.theme = 666; final String fileName = "protoUtilsWriteToFile"; final Context context = RuntimeEnvironment.application; context.deleteFile(fileName); ProtoUtils.writeToFile(context, fileName, message); final InputStream is = context.openFileInput(fileName); final byte[] readBytes = ByteStreams.toByteArray(is); assertNotNull(readBytes); final SettingsProto.Settings read = new SettingsProto.Settings() .mergeFrom(CodedInputByteBufferNano.newInstance(readBytes)); assertEquals(message.scrobbleEnabled, read.scrobbleEnabled); assertEquals(message.theme, read.theme); }
public static void writeToFile(@NonNull final Context context, @NonNull final String fileName, @NonNull final MessageNano messageNano) { final byte[] output; try { output = toByteArray(messageNano); } catch (IOException e) { Log.w(TAG, e); return; } FileUtils.writeOrDeletePrivateFile(context, fileName, output); }
ProtoUtils { public static void writeToFile(@NonNull final Context context, @NonNull final String fileName, @NonNull final MessageNano messageNano) { final byte[] output; try { output = toByteArray(messageNano); } catch (IOException e) { Log.w(TAG, e); return; } FileUtils.writeOrDeletePrivateFile(context, fileName, output); } }
ProtoUtils { public static void writeToFile(@NonNull final Context context, @NonNull final String fileName, @NonNull final MessageNano messageNano) { final byte[] output; try { output = toByteArray(messageNano); } catch (IOException e) { Log.w(TAG, e); return; } FileUtils.writeOrDeletePrivateFile(context, fileName, output); } private  ProtoUtils(); }
ProtoUtils { public static void writeToFile(@NonNull final Context context, @NonNull final String fileName, @NonNull final MessageNano messageNano) { final byte[] output; try { output = toByteArray(messageNano); } catch (IOException e) { Log.w(TAG, e); return; } FileUtils.writeOrDeletePrivateFile(context, fileName, output); } private  ProtoUtils(); @NonNull static byte[] toByteArray(@NonNull final MessageNano messageNano); static void writeToFile(@NonNull final Context context,
            @NonNull final String fileName,
            @NonNull final MessageNano messageNano); @Nullable static T readFromFile(@NonNull final Context context,
            @NonNull final String fileName,
            @NonNull final T obj); @NonNull static T readFromFileNonNull(@NonNull final Context context,
            @NonNull final String fileName,
            @NonNull final T obj); }
ProtoUtils { public static void writeToFile(@NonNull final Context context, @NonNull final String fileName, @NonNull final MessageNano messageNano) { final byte[] output; try { output = toByteArray(messageNano); } catch (IOException e) { Log.w(TAG, e); return; } FileUtils.writeOrDeletePrivateFile(context, fileName, output); } private  ProtoUtils(); @NonNull static byte[] toByteArray(@NonNull final MessageNano messageNano); static void writeToFile(@NonNull final Context context,
            @NonNull final String fileName,
            @NonNull final MessageNano messageNano); @Nullable static T readFromFile(@NonNull final Context context,
            @NonNull final String fileName,
            @NonNull final T obj); @NonNull static T readFromFileNonNull(@NonNull final Context context,
            @NonNull final String fileName,
            @NonNull final T obj);  }