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


Java RandomAccessFile.read方法代码示例

本文整理汇总了Java中java.io.RandomAccessFile.read方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.read方法的具体用法?Java RandomAccessFile.read怎么用?Java RandomAccessFile.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.RandomAccessFile的用法示例。


在下文中一共展示了RandomAccessFile.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeCrcOfCentralDir

import java.io.RandomAccessFile; //导入方法依赖的package包/类
static long computeCrcOfCentralDir(RandomAccessFile raf, CentralDirectory dir)
        throws IOException {
    CRC32 crc = new CRC32();
    long stillToRead = dir.size;
    raf.seek(dir.offset);
    int length = (int) Math.min(BUFFER_SIZE, stillToRead);
    byte[] buffer = new byte[BUFFER_SIZE];
    length = raf.read(buffer, 0, length);
    while (length != -1) {
        crc.update(buffer, 0, length);
        stillToRead -= length;
        if (stillToRead == 0) {
            break;
        }
        length = (int) Math.min(BUFFER_SIZE, stillToRead);
        length = raf.read(buffer, 0, length);
    }
    return crc.getValue();
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:20,代码来源:ZipUtil.java

示例2: transferData

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public static void transferData(
        final RandomAccessFile in, 
        final OutputStream out, 
        final long max,
        final Progress progress) throws IOException {
    final byte[] buffer = new byte[FileUtils.BUFFER_SIZE];
    
    long total = 0;
    int length = 0;
    
    progress.setPercentage(Progress.START);
    while (((length = in.read(buffer)) != -1) && (total < max)) {
        total += length;
        out.write(
                buffer, 
                0, 
                (int) (total < max ? length : length - (total - max)));
        
        if (total < max) {
            progress.setPercentage(Progress.COMPLETE * total / max);
        }
    }
    progress.setPercentage(Progress.COMPLETE);
    
    out.flush();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:StreamUtils.java

示例3: read

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * The <code>read()</code> method reads the header from the specified input stream.
 * It loads the identification section and checks that the header is present by testing against
 * the magic ELF values, and reads the rests of the data section, initializes the ELF section.
 * @param fs the input stream from which to read the ELF header
 * @throws IOException if there is a problem reading from the input stream
 */
public void read(RandomAccessFile fs) throws IOException, FormatError {
    // read the indentification string
    if (fs.length() < EI_NIDENT) {
        throw new FormatError();
    }
    int index = 0;
    //String abc = fs.readLine();
    //System.out.println(abc);
    while (index < EI_NIDENT) {
        index += fs.read(e_ident, index, EI_NIDENT - index);
    }

    checkIdent();
    final ELFDataInputStream is = new ELFDataInputStream(this, fs);
    if (is32Bit()) {
        // read a 32-bit header.
        readHeader32(is);
    } else if (is64Bit()) {
        // read a 64-bit header.
        readHeader64(is);
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:30,代码来源:ELFHeader.java

示例4: readRawPacketData

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Retrieve the raw VorbisComment packet data, does not include the OggVorbis header
 *
 * @param raf
 * @return
 * @throws CannotReadException if unable to find vorbiscomment header
 * @throws IOException
 */
public byte[] readRawPacketData(RandomAccessFile raf) throws CannotReadException, IOException {
    logger.fine("Read 1st page");
    //1st page = codec infos
    OggPageHeader pageHeader = OggPageHeader.read(raf);
    //Skip over data to end of page header 1
    raf.seek(raf.getFilePointer() + pageHeader.getPageLength());

    logger.fine("Read 2nd page");
    //2nd page = comment, may extend to additional pages or not , may also have setup header
    pageHeader = OggPageHeader.read(raf);

    //Now at start of packets on page 2 , check this is the vorbis comment header 
    byte[] b = new byte[VorbisHeader.FIELD_PACKET_TYPE_LENGTH + VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH];
    raf.read(b);
    if (!isVorbisCommentHeader(b)) {
        throw new CannotReadException("Cannot find comment block (no vorbiscomment header)");
    }

    //Convert the comment raw data which maybe over many pages back into raw packet
    byte[] rawVorbisCommentData = convertToVorbisCommentPacket(pageHeader, raf);
    return rawVorbisCommentData;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:31,代码来源:OggVorbisTagReader.java

示例5: ColonizationMapLoader

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public ColonizationMapLoader(File file) throws FileNotFoundException, IOException {

        try {
            RandomAccessFile reader = new RandomAccessFile(file, "r");
            reader.read(header);

            int size = header[WIDTH] * header[HEIGHT];
            layer1 = new byte[size];
            reader.read(layer1);
        } catch (FileNotFoundException fe) {
            logger.log(Level.SEVERE, "File (" + file + ") was not found.", fe);
        } catch (IOException e) {
            logger.log(Level.SEVERE, "File (" + file + ") is corrupt and cannot be read.", e);
        }

    }
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:17,代码来源:ColonizationMapLoader.java

示例6: read

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public synchronized int read(final byte[] chunk, final Long offset) throws IOException {
    final RandomAccessFile file = random();
    if(offset < file.length()) {
        file.seek(offset);
        if(chunk.length + offset > file.length()) {
            return file.read(chunk, 0, (int) (file.length() - offset));
        }
        else {
            return file.read(chunk, 0, chunk.length);
        }
    }
    else {
        final NullInputStream nullStream = new NullInputStream(length);
        if(nullStream.available() > 0) {
            nullStream.skip(offset);
            return nullStream.read(chunk, 0, chunk.length);
        }
        else {
            return IOUtils.EOF;
        }
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:24,代码来源:FileBuffer.java

示例7: readEntry64

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private Entry64 readEntry64(RandomAccessFile fis, ELFDataInputStream is) throws IOException {
    final Entry64 e = new Entry64();
    e.sh_name      = is.read_Elf64_Word();   // 4
    e.sh_type      = is.read_Elf64_Word();   // 4
    e.sh_flags     = is.read_Elf64_XWord();  // 8
    e.sh_addr      = is.read_Elf64_Addr();   // 8
    e.sh_offset    = is.read_Elf64_Off();    // 8
    e.sh_size      = is.read_Elf64_XWord();  // 8
    e.sh_link      = is.read_Elf64_Word();   // 4
    e.sh_info      = is.read_Elf64_Word();   // 4
    e.sh_addralign = is.read_Elf64_XWord();  // 8
    e.sh_entsize   = is.read_Elf64_XWord();  // 8


    for (int pad = ELF64_SHTENT_SIZE; pad < header.e_shentsize; pad++) {
        fis.read();
    }
    return e;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:20,代码来源:ELFSectionHeaderTable.java

示例8: preloadLineTile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public void preloadLineTile(int y, int length,int band) {
    if (y < 0) {
        return;
    }
    //if(preloadedDataSLC==null){
     preloadedInterval = new int[]{y, y + length};
     //y+4 skips the first 4 lines of offset
     int tileOffset = (y+4) * ( getImage(band).xSize * 4 + xOffset);
     preloadedDataSLC = new byte[( getImage(band).xSize * 4 + xOffset) * length];
     //preloadedDataSLC = new byte[getWidth()*getHeight()];
     try {
         File fimg=tiffImages.get("HH").getImageFile();
     	fss = new RandomAccessFile(fimg.getAbsolutePath(), "r");
     	fss.seek(tileOffset);
         fss.read(preloadedDataSLC);
         fss.close();
     } catch (IOException e) {
     	logger.error(e.getMessage()+ "  cannot preload the line tile",e);
     }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:22,代码来源:TerrasarXImage_SLC.java

示例9: readByteFromFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public byte[] readByteFromFile(byte[] buf, String file_name) throws IOException {
  RandomAccessFile f = new RandomAccessFile(file_name, "r");
  byte[] b = new byte[(int) f.length()];
  f.read(b);
  f.close();
  return b;
}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:8,代码来源:Util.java

示例10: endsWithNewline

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private static boolean endsWithNewline(RandomAccessFile randomAccessFile) throws IOException {
  if (randomAccessFile.length() < 1) {
    return false;
  }
  randomAccessFile.seek(randomAccessFile.length() - 1);
  byte[] chars = new byte[1];
  if (randomAccessFile.read(chars) < 1) {
    return false;
  }
  String ch = new String(chars);
  return "\n".equals(ch) || "\r".equals(ch);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:13,代码来源:MissingNewLineAtEndOfFileCheck.java

示例11: BatchReader

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public BatchReader(long filePointer, File mafFile, ArrayList<Object[]> subjectInfo, boolean verbose) {
	try {
		raf = new RandomAccessFile(mafFile, "r");
		raf.seek(filePointer);
		readChars = raf.read(buffer);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	this.verbose = verbose;
	this.subjectInfo = subjectInfo;
}
 
开发者ID:BenjaminAlbrecht84,项目名称:DAA_Converter,代码行数:13,代码来源:MAF_Converter.java

示例12: readFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public static byte[] readFile(File file) throws Exception{
    RandomAccessFile raf = new RandomAccessFile(file, "r");
    byte[] ret = new byte[(int)raf.length()];
    raf.read(ret);
    raf.close();
    return ret;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:8,代码来源:IOUtils.java

示例13: loadAllReferences

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void loadAllReferences() {
	try {
		RandomAccessFile raf = new RandomAccessFile(daaFile, "r");
		try {

			raf.seek(getLocationOfBlockInFile(refNamesBlockIndex));

			referenceNames = new byte[(int) dbSeqsUsed][];
			referenceLocations = new long[1 + ((int) dbSeqsUsed >>> referenceLocationChunkBits)];
			for (int i = 0; i < (int) dbSeqsUsed; i++) {
				if ((i & (referenceLocationChunkSize - 1)) == 0) {
					referenceLocations[i >>> referenceLocationChunkBits] = raf.getFilePointer();
				}
				int c = raf.read();
				while (c != 0)
					c = raf.read();
			}

			refLengths = new int[(int) dbSeqsUsed];
			for (int i = 0; i < dbSeqsUsed; i++) {
				ByteBuffer buffer = ByteBuffer.allocate(4);
				buffer.order(ByteOrder.LITTLE_ENDIAN);
				raf.read(buffer.array());
				refLengths[i] = buffer.getInt();
			}

		} finally {
			raf.close();
		}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:BenjaminAlbrecht84,项目名称:DAA_Converter,代码行数:35,代码来源:DAA_Header.java

示例14: readEntry64

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private Entry64 readEntry64(RandomAccessFile f, ELFDataInputStream is) throws IOException {
    final Entry64 e = new Entry64();
    // note the order of fields is different in the 64 bit version.
    e.st_name  = is.read_Elf64_Word();
    e.st_info  = is.read_Elf64_uchar();
    e.st_other = is.read_Elf64_uchar();
    e.st_shndx = is.read_Elf64_Half();
    e.st_value = is.read_Elf64_Addr();
    e.st_size  = is.read_Elf64_XWord();
    for (int pad = ELF64_STENT_SIZE; pad < entry.getEntrySize(); pad++) {
        f.read();
    }
    return e;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:15,代码来源:ELFSymbolTable.java

示例15: findLastDate

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private Date findLastDate(RandomAccessFile raf) throws IOException {
	Date date = null;
	long pos = raf.length() - 2;
	
	while (date == null && pos > 0) {
		do {
			raf.seek(pos);
			--pos;
		} while (raf.read() != 10 && pos > 0); // '\n'
		
		date = parseDate(raf);
	}
	
	return date;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:16,代码来源:TemporalInputStream.java


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