Back to project page android_retrieval_system.
The source code is released under:
GNU General Public License
If you think the Android project android_retrieval_system listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * This file is part of Android retrieval system project. * //from www .j a v a 2 s .co m * Android retrieval system is free software: you can redistribute it * and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * Android retrieval system is distributed in the hope that * it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Android retrieval system. If not, see <http://www.gnu.org/licenses/>. */ package net.deerhunter.ars.protocol.packets; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; /** * This class contains all the information and methods needed to send the * image to the server. * * @author DeerHunter (vityokkv73@gmail.com) */ public class ImagePacket extends BasePacket { private String displayName; private String filePath; private int storeId; private long dateAdded; private byte[] image; private byte[] binaryPacket; /** * Constructs a new ImagePacket using all necessary parameters. * * @param displayName Name of the image * @param filePath Full path to the image * @param storeId Store ID of the image in the database * @param dateAdded Date when the image was added * @param image Byte array of the image */ public ImagePacket(String displayName, String filePath, int storeId, long dateAdded, byte[] image) { this.displayName = displayName; this.filePath = filePath; this.storeId = storeId; this.dateAdded = dateAdded; this.image = image; generateBinaryPacket(); } /** * Method generates a binary representation of a image packet. */ private void generateBinaryPacket() { ByteArrayOutputStream outputArray = new ByteArrayOutputStream(100000); try { Charset UTF8Charset = Charset.forName("UTF-8"); formatWriteStringToArray(outputArray, displayName, UTF8Charset); formatWriteStringToArray(outputArray, filePath, UTF8Charset); ByteBuffer intArray = ByteBuffer.allocate(4); intArray.putInt(storeId); outputArray.write(intArray.array()); ByteBuffer longArray = ByteBuffer.allocate(8); longArray.putLong(dateAdded); outputArray.write(longArray.array()); intArray.clear(); intArray.putInt(image.length); outputArray.write(intArray.array()); outputArray.write(image); binaryPacket = outputArray.toByteArray(); } catch (IOException e) {} } /** * Method returns name of the image. * * @return Name of the image */ public String getDisplayName() { return displayName; } /** * Method returns a path to the image. * * @return Path to the image */ public String getFilePath() { return filePath; } /** * Method returns a store ID of the image. * * @return Store ID of the image */ public int getStoreId() { return storeId; } /** * Method returns a date when the image was added. * * @return Date when the image was added */ public long getDateAdded() { return dateAdded; } /** * Method returns a byte array of the image. * * @return Byte array of the image */ public byte[] getImage() { return image; } /** * Method returns a binary representation of a thumbnail packet. * * @return binary representation of a thumbnail packet */ public byte[] getBinaryPacket() { return binaryPacket; } @Override public String toString() { StringBuilder builder = new StringBuilder(300); builder.append("ImagePacket { "); builder.append("displayName = " + displayName); builder.append(", filePath = " + filePath); builder.append(", storeId = " + storeId); builder.append(", dateAdded = " + dateAdded); builder.append(" }"); return builder.toString(); } }