本文整理匯總了Java中java.io.RandomAccessFile.readFully方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomAccessFile.readFully方法的具體用法?Java RandomAccessFile.readFully怎麽用?Java RandomAccessFile.readFully使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.readFully方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readChunk
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static RealChunk readChunk(RandomAccessFile raf)
throws CannotReadException, IOException {
final String id = Utils.readString(raf, 4);
final int size = Utils.readUint32AsInt(raf);
if (size < 8) {
throw new CannotReadException(
"Corrupt file: RealAudio chunk length at position "
+ (raf.getFilePointer() - 4)
+ " cannot be less than 8");
}
if (size > (raf.length() - raf.getFilePointer() + 8)) {
throw new CannotReadException(
"Corrupt file: RealAudio chunk length of " + size
+ " at position " + (raf.getFilePointer() - 4)
+ " extends beyond the end of the file");
}
final byte[] bytes = new byte[size - 8];
raf.readFully(bytes);
return new RealChunk(id, size, bytes);
}
示例2: getAudioInfo
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static AudioInfo getAudioInfo(File file) {
try {
byte header[] = new byte[12];
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.readFully(header, 0, 8);
randomAccessFile.close();
InputStream input = new BufferedInputStream(new FileInputStream(file));
if (header[4] == 'f' && header[5] == 't' && header[6] == 'y' && header[7] == 'p') {
return new M4AInfo(input);
} else {
return new MP3Info(input, file.length());
}
} catch (Exception e) {
return null;
}
}
示例3: readChunk
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static RealChunk readChunk(RandomAccessFile raf)
throws CannotReadException, IOException {
final String id = Utils.readString(raf, 4);
final int size = (int)Utils.readUint32(raf);
if (size < 8) {
throw new CannotReadException(
"Corrupt file: RealAudio chunk length at position "
+ (raf.getFilePointer() - 4)
+ " cannot be less than 8");
}
if (size > (raf.length() - raf.getFilePointer() + 8)) {
throw new CannotReadException(
"Corrupt file: RealAudio chunk length of " + size
+ " at position " + (raf.getFilePointer() - 4)
+ " extends beyond the end of the file");
}
final byte[] bytes = new byte[size - 8];
raf.readFully(bytes);
return new RealChunk(id, size, bytes);
}
示例4: checkFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static void checkFile(String filePath, String header) {
try {
byte[] fileContent;
RandomAccessFile randomFile = new RandomAccessFile(filePath, "rw");
fileContent = new byte[(int) randomFile.length()];
randomFile.readFully(fileContent);
randomFile.close();
String text = new String(fileContent);
if (text.indexOf("Copyright IBM Corp") != -1) {
return;
}
if (text.indexOf(header) == -1) {
failed = true;
failedFilesCollection.add(filePath);
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: readBytes
import java.io.RandomAccessFile; //導入方法依賴的package包/類
protected static byte[] readBytes(File file, int fixedLength) throws IOException {
if (!file.exists()) {
throw new FileNotFoundException("Not found: " + file);
}
if (!file.isFile()) {
throw new IOException("Not a file: " + file);
}
long len = file.length();
if (len >= Integer.MAX_VALUE) {
throw new IOException("File is larger then max array size");
}
if (fixedLength > -1 && fixedLength < len) {
len = fixedLength;
}
byte[] bytes = new byte[(int) len];
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.readFully(bytes);
randomAccessFile.close();
return bytes;
}
示例6: checkFileFormat
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static boolean checkFileFormat(RandomAccessFile file)
throws IOException {
if (file.length() < Loader.MINIMUM_FILE_LENGTH)
return false;
byte[] magic = new byte[MAGIC_HEADER.length];
file.readFully(magic);
if (!Arrays.equals(MAGIC_HEADER, magic))
return false;
return true;
}
示例7: readFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private static byte[] readFile(final URL classUrl)
throws IOException, URISyntaxException {
URI uri = new URI(classUrl.toString());
File file = new File(uri);
RandomAccessFile f = new RandomAccessFile(file, "r"); // NOI18N
byte[] buf = new byte[(int) f.length()];
f.readFully(buf);
//System.err.println("Size "+buf.length);
f.close();
return buf;
}
示例8: fastSignInfo
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public static int fastSignInfo(File file) {
int v1 = SIGNED_NOT;
int v2 = SIGNED_NOT;
try {
ZipFile zip = new ZipFile(file);
if (zip.getEntry("META-INF/CERT.RSA") != null) {
v1 = SIGNED_V1;
}
Field archiveField = ZipFile.class.getDeclaredField("archive");
archiveField.setAccessible(true);
final RandomAccessFile archive = (RandomAccessFile) archiveField.get(zip);
Method positionAtCentralDirectory = ZipFile.class.getDeclaredMethod("positionAtCentralDirectory");
positionAtCentralDirectory.setAccessible(true);
positionAtCentralDirectory.invoke(zip);
long centralDirectoryOffset = archive.getFilePointer();
archive.seek(centralDirectoryOffset - 24);
byte[] buffer = new byte[24];
archive.readFully(buffer);
zip.close();
ByteBuffer footer = ByteBuffer.wrap(buffer);
footer.order(ByteOrder.LITTLE_ENDIAN);
if ((footer.getLong(8) == APK_SIG_BLOCK_MAGIC_LO)
&& (footer.getLong(16) == APK_SIG_BLOCK_MAGIC_HI)) {
v2 = SIGNED_V2;
}
} catch (IOException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
}
return v1 | v2;
}
示例9: readInstallationFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
/**
* Read state from saved file
* @param installation File
* @return String
* @throws IOException
*/
private static String readInstallationFile(File installation) throws IOException {
RandomAccessFile f = new RandomAccessFile(installation, "r");// read only mode
byte[] bytes = new byte[(int) f.length()];
f.readFully(bytes);
f.close();
return new String(bytes);
}
示例10: parseEocdRecord
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private static EocdRecord parseEocdRecord(RandomAccessFile raf, long offset, boolean isZip64)
throws IOException {
long numEntries;
long centralDirOffset;
raf.seek(offset);
byte[] eocd = new byte[18];
raf.readFully(eocd);
BufferIterator it = HeapBufferIterator.iterator(eocd, 0, eocd.length, ByteOrder
.LITTLE_ENDIAN);
if (isZip64) {
numEntries = -1;
centralDirOffset = -1;
it.skip(16);
} else {
int diskNumber = it.readShort() & 65535;
int diskWithCentralDir = it.readShort() & 65535;
numEntries = (long) (it.readShort() & 65535);
int totalNumEntries = it.readShort() & 65535;
it.skip(4);
centralDirOffset = ((long) it.readInt()) & 4294967295L;
if (!(numEntries == ((long) totalNumEntries) && diskNumber == 0 && diskWithCentralDir
== 0)) {
throw new ZipException("Spanned archives not supported");
}
}
return new EocdRecord(numEntries, centralDirOffset, it.readShort() & 65535);
}
示例11: readInstallationFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private static String readInstallationFile(File installation) throws IOException {
RandomAccessFile f = new RandomAccessFile(installation, "r");
byte[] bytes = new byte[(int) f.length()];
f.readFully(bytes);
f.close();
return new String(bytes);
}
示例12: readFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
/**
* Reads and returns the full contents of the specified file.
*
* @param file File to read
* @return byte[] containing full contents of file
* @throws IOException if there is an I/O error while reading the file
*/
private byte[] readFile(File file) throws IOException {
RandomAccessFile raf = new RandomAccessFile(file, "r");
byte[] buffer = new byte[(int) raf.length()];
raf.readFully(buffer);
raf.close();
return buffer;
}
示例13: a
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private static byte[] a(RandomAccessFile randomAccessFile) throws IOException {
int i = 1;
long length = randomAccessFile.length() - 22;
randomAccessFile.seek(length);
byte[] bytes = a.getBytes();
byte read = randomAccessFile.read();
while (read != (byte) -1) {
if (read == bytes[0] && randomAccessFile.read() == bytes[1] && randomAccessFile.read() == bytes[2] && randomAccessFile.read() == bytes[3]) {
break;
}
length--;
randomAccessFile.seek(length);
read = randomAccessFile.read();
}
i = 0;
if (i == 0) {
throw new ZipException("archive is not a ZIP archive");
}
randomAccessFile.seek((16 + length) + 4);
byte[] bArr = new byte[2];
randomAccessFile.readFully(bArr);
i = new ZipShort(bArr).getValue();
if (i == 0) {
return null;
}
bArr = new byte[i];
randomAccessFile.read(bArr);
return bArr;
}
示例14: readArmAttributes
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private static boolean readArmAttributes(RandomAccessFile in, ElfData elf) throws IOException {
byte[] bytes = new byte[elf.sh_size];
in.seek(elf.sh_offset);
in.readFully(bytes);
// wrap bytes in a ByteBuffer to force endianess
ByteBuffer buffer = ByteBuffer.wrap(bytes);
buffer.order(elf.order);
//http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf
//http://infocenter.arm.com/help/topic/com.arm.doc.ihi0045d/IHI0045D_ABI_addenda.pdf
if (buffer.get() != 'A') // format-version
return false;
// sub-sections loop
while (buffer.remaining() > 0) {
int start_section = buffer.position();
int length = buffer.getInt();
String vendor = getString(buffer);
if (vendor.equals("aeabi")) {
// tags loop
while (buffer.position() < start_section + length) {
int start = buffer.position();
int tag = buffer.get();
int size = buffer.getInt();
// skip if not Tag_File, we don't care about others
if (tag != 1) {
buffer.position(start + size);
continue;
}
// attributes loop
while (buffer.position() < start + size) {
tag = getUleb128(buffer);
if (tag == 6) { // CPU_arch
int arch = getUleb128(buffer);
elf.att_arch = CPU_archs[arch];
} else if (tag == 27) { // ABI_HardFP_use
getUleb128(buffer);
elf.att_fpu = true;
} else {
// string for 4=CPU_raw_name / 5=CPU_name / 32=compatibility
// string for >32 && odd tags
// uleb128 for other
tag %= 128;
if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
getString(buffer);
else
getUleb128(buffer);
}
}
}
break;
}
}
return true;
}
示例15: sendSticker
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public void sendSticker(TLRPC.Document document, long peer, MessageObject replyingMessageObject, boolean asAdmin) {
if (document == null) {
return;
}
if ((int) peer == 0) {
int high_id = (int) (peer >> 32);
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id);
if (encryptedChat == null) {
return;
}
if (document.thumb instanceof TLRPC.TL_photoSize) {
File file = FileLoader.getPathToAttach(document.thumb, true);
if (file.exists()) {
try {
int len = (int) file.length();
byte[] arr = new byte[(int) file.length()];
RandomAccessFile reader = new RandomAccessFile(file, "r");
reader.readFully(arr);
TLRPC.TL_document newDocument = new TLRPC.TL_document();
newDocument.thumb = new TLRPC.TL_photoCachedSize();
newDocument.thumb.location = document.thumb.location;
newDocument.thumb.size = document.thumb.size;
newDocument.thumb.w = document.thumb.w;
newDocument.thumb.h = document.thumb.h;
newDocument.thumb.type = document.thumb.type;
newDocument.thumb.bytes = arr;
newDocument.id = document.id;
newDocument.access_hash = document.access_hash;
newDocument.date = document.date;
newDocument.mime_type = document.mime_type;
newDocument.size = document.size;
newDocument.dc_id = document.dc_id;
newDocument.attributes = document.attributes;
if (newDocument.mime_type == null) {
newDocument.mime_type = "";
}
document = newDocument;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
}
SendMessagesHelper.getInstance().sendMessage((TLRPC.TL_document) document, null, null, peer, replyingMessageObject, asAdmin, null, null);
}