If you think the Android project remoteyourcam-usb listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/**
* Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
*//www.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.remoteyourcam.usb.ptp;
import java.nio.ByteBuffer;
import android.util.Log;
publicclass PacketUtil {
publicstaticint[] readU32Array(ByteBuffer b) {
int len = b.getInt();
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.getInt();
}
return a;
}
publicstaticint[] readU16Array(ByteBuffer b) {
int len = b.getInt();
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.getShort() & 0xFFFF;
}
return a;
}
publicstaticvoid writeU16Array(ByteBuffer b, int[] a) {
b.putInt(a.length);
for (int v : a) {
b.putShort((short) v);
}
}
publicstaticint[] readU8Array(ByteBuffer b) {
int len = b.getInt();
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.get() & 0xFF;
}
return a;
}
publicstaticint[] readU32Enumeration(ByteBuffer b) {
int len = b.getShort() & 0xFFFF;
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.getInt();
}
return a;
}
publicstaticint[] readS16Enumeration(ByteBuffer b) {
int len = b.getShort() & 0xFFFF;
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.getShort();
}
return a;
}
publicstaticint[] readU16Enumeration(ByteBuffer b) {
int len = b.getShort() & 0xFFFF;
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.getShort() & 0xFFFF;
}
return a;
}
publicstaticint[] readU8Enumeration(ByteBuffer b) {
int len = b.getShort() & 0xFFFF;
int[] a = newint[len];
for (int i = 0; i < len; ++i) {
a[i] = b.get() & 0xFF;
}
return a;
}
publicstatic String readString(ByteBuffer b) {
int len = b.get() & 0xFF;
if (len > 0) {
char[] ch = newchar[len - 1];
for (int i = 0; i < len - 1; ++i) {
ch[i] = b.getChar();
}
// read '\0'
b.getChar();
return String.copyValueOf(ch);
}
return"";
}
publicstaticvoid writeString(ByteBuffer b, String s) {
b.put((byte) s.length());
if (s.length() > 0) {
for (int i = 0; i < s.length(); ++i) {
b.putShort((short) s.charAt(i));
}
b.putShort((short) 0);
}
}
publicstatic String hexDumpToString(byte[] a, int offset, int len) {
int lines = len / 16;
int rest = len % 16;
StringBuilder b = new StringBuilder((lines + 1) * 97);
for (int i = 0; i < lines; ++i) {
b.append(String.format("%04x ", i * 16));
for (int k = 0; k < 16; ++k) {
b.append(String.format("%02x ", a[offset + i * 16 + k]));
}
for (int k = 0; k < 16; ++k) {
char ch = (char) a[offset + i * 16 + k];
b.append(ch >= 0x20 && ch <= 0x7E ? ch : '.');
}
b.append('\n');
}
if (rest != 0) {
b.append(String.format("%04x ", lines * 16));
for (int k = 0; k < rest; ++k) {
b.append(String.format("%02x ", a[offset + lines * 16 + k]));
}
for (int k = 0; k < (16 - rest) * 3; ++k) {
b.append(' ');
}
for (int k = 0; k < rest; ++k) {
char ch = (char) a[offset + lines * 16 + k];
b.append(ch >= 0x20 && ch <= 0x7E ? ch : '.');
}
b.append('\n');
}
return b.toString();
}
publicstaticvoid logHexdump(String tag, byte[] a, int offset, int len) {
Log.i(tag, hexDumpToString(a, offset, len));
}
publicstaticvoid logHexdump(String tag, byte[] a, int len) {
logHexdump(tag, a, 0, len);
}
}