当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.readFully方法代码示例

本文整理汇总了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);
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:21,代码来源:RealChunk.java

示例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;
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:17,代码来源:AudioInfo.java

示例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);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:21,代码来源:RealChunk.java

示例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();
    }

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:HeadersTest.java

示例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;
}
 
开发者ID:Xlongshu,项目名称:EasyController,代码行数:24,代码来源:FileLFUCache.java

示例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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:FSImageUtil.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ClassBytesLoader.java

示例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;
}
 
开发者ID:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:31,代码来源:ApkUtils.java

示例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);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:15,代码来源:FirstRun.java

示例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);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:TinkerZipFile.java

示例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);
}
 
开发者ID:tranleduy2000,项目名称:text_converter,代码行数:8,代码来源:Installation.java

示例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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:VersionInfoMojo.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:30,代码来源:ApkExternalInfoTool.java

示例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;
}
 
开发者ID:pedroSG94,项目名称:vlc-example-streamplayer,代码行数:58,代码来源:VLCUtil.java

示例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);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:47,代码来源:SendMessagesHelper.java


注:本文中的java.io.RandomAccessFile.readFully方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。