Back to project page PasswordDroid.
The source code is released under:
GNU General Public License
If you think the Android project PasswordDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.wuthoehle.passworddroid.service.model;/* Copyright (c) 2015 Marco Huenseler <marcoh.huenseler+git@gmail.com> * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /*from w w w. ja v a 2 s. com*/ import android.util.Log; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.util.Queue; public class FileFormat { public static final byte ID_DATABASE = 0; public static final byte ID_CATEGORY = 1; public static final byte ID_ENTRY = 2; public static final byte ID_COUNTABLE = 3; public static final byte ID_CUSTOMIZABLE = 4; public static final byte ID_COMMENTABLE = 5; public static final byte ID_SALTABLE = 6; public static byte getByte(Queue<Byte> bytestream) throws FileFormat.MalformedDatabaseFileException { byte result = 0; if (bytestream.size() == 0) { throw new FileFormat.MalformedDatabaseFileException("No byte left in queue!"); } return bytestream.remove(); } public static int getInteger(Queue<Byte> bytestream) throws FileFormat.MalformedDatabaseFileException { int result = 0; byte[] read = new byte[4]; if (bytestream.size() < 4) { throw new FileFormat.MalformedDatabaseFileException("No integer left in queue!"); } for (int i = 0; i < 4; i++) { read[i] = bytestream.remove(); } result = ByteBuffer.wrap(read).getInt(); return result; } public static String getString(Queue<Byte> bytestream, int size) throws FileFormat.MalformedDatabaseFileException { String result = ""; byte[] read_string = new byte[size]; if (bytestream.size() < size) { throw new FileFormat.MalformedDatabaseFileException("No string left in queue!"); } for (int i = 0; i < size; i++) { read_string[i] = bytestream.remove(); } if (read_string.length >= 0) { try { result = new String(read_string, "UTF-8"); } catch (UnsupportedEncodingException e) { Log.d("Entry Factory", "Unable to parse string!"); e.printStackTrace(); } } return result; } public static class MalformedDatabaseFileException extends IllegalArgumentException { public MalformedDatabaseFileException() { } public MalformedDatabaseFileException(String detailMessage) { super(detailMessage); } public MalformedDatabaseFileException(String message, Throwable cause) { super(message, cause); } public MalformedDatabaseFileException(Throwable cause) { super(cause); } } }