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


Java RandomAccessFile.length方法代码示例

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


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

示例1: fillPhotoSizeWithBytes

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public static void fillPhotoSizeWithBytes(TLRPC.PhotoSize photoSize) {
    if (photoSize == null || photoSize.bytes != null) {
        return;
    }
    File file = FileLoader.getPathToAttach(photoSize, true);
    try {
        RandomAccessFile f = new RandomAccessFile(file, "r");
        int len = (int) f.length();
        if (len < 20000) {
            photoSize.bytes = new byte[(int) f.length()];
            f.readFully(photoSize.bytes, 0, photoSize.bytes.length);
        }
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:17,代码来源:ImageLoader.java

示例2: RandomAccessMmapObject

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public RandomAccessMmapObject(final RandomAccessFile randomAccessFile, String mode)
    throws IOException, IllegalArgumentException {
  if (randomAccessFile.length() > Integer.MAX_VALUE) {
    throw new IllegalArgumentException("Only files up to 2GiB in size are supported.");
  }

  FileChannel.MapMode mapMode;
  if (mode.equals("r")) {
    mapMode = FileChannel.MapMode.READ_ONLY;
  } else {
    mapMode = FileChannel.MapMode.READ_WRITE;
  }

  mFileChannel = randomAccessFile.getChannel();
  mByteBuffer = mFileChannel.map(mapMode, 0, randomAccessFile.length());
  mByteBuffer.position(0);
  mShouldDeleteFileOnRelease = false;
  mFile = null;
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:20,代码来源:RandomAccessObject.java

示例3: open

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public long open(DataSpec dataSpec) throws FileDataSourceException {
  try {
    uri = dataSpec.uri;
    file = new RandomAccessFile(dataSpec.uri.getPath(), "r");
    file.seek(dataSpec.position);
    bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position
        : dataSpec.length;
    if (bytesRemaining < 0) {
      throw new EOFException();
    }
  } catch (IOException e) {
    throw new FileDataSourceException(e);
  }

  opened = true;
  if (listener != null) {
    listener.onTransferStart(this, dataSpec);
  }

  return bytesRemaining;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:FileDataSource.java

示例4: setDumpBuffer

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void setDumpBuffer(RandomAccessFile file) throws IOException {
    long length = file.length();

    try {
        if (length > Integer.MAX_VALUE) {
            dumpBuffer = new LongMemoryMappedData(file, length);
        } else {
            dumpBuffer = new MemoryMappedData(file, length);
        }
    } catch (IOException ex) {
        if (ex.getCause() instanceof OutOfMemoryError) {
            dumpBuffer = new FileData(file, length);
        } else {
            throw ex;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AbstractLongMap.java

示例5: 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

示例6: getLength

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public long
getLength(
	RandomAccessFile		raf )

	throws FMFileManagerException
{
	try{
		AEThread2.setDebug( owner );

		return( raf.length());

	}catch( Throwable e ){

		throw( new FMFileManagerException( "getLength fails", e ));
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:18,代码来源:FMFileAccessLinear.java

示例7: 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

示例8: Descriptor

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public Descriptor(File file, String mode) throws IOException {
  this.file = file;
  this.mode = mode;
  isOpen=true;
  RandomAccessFile raf = new RandomAccessFile(file, mode);
  length=raf.length();
  fileMap.put(Thread.currentThread().getName(), raf);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:9,代码来源:FSDirectory.java

示例9: ensureLockState

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public LockState ensureLockState(RandomAccessFile lockFileAccess) throws IOException {
    if (lockFileAccess.length() == 0) {
        // File did not exist before locking, use some initial state
        LockState state = protocol.createInitialState();
        writeState(lockFileAccess, state);
        return state;
    } else {
        return readState(lockFileAccess);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:11,代码来源:LockStateAccess.java

示例10: removeLastLine

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public static void removeLastLine(String filename, int len) {
	 try{
            RandomAccessFile raf = new RandomAccessFile(filename, "rw");
            long length = raf.length();
           
            raf.setLength(length - len);
           
            raf.close();
            }
	 	
	 		catch(Exception ex){
            ex.printStackTrace();
            }
}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:15,代码来源:Tail.java

示例11: read

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public AiffAudioHeader read(RandomAccessFile raf) throws CannotReadException, IOException {
    if (raf.length() < 4) {
        //Empty File
        throw new CannotReadException("Not an AIFF file; too short");
    }
    return null;     // TODO stub
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:8,代码来源:AiffInfoReader.java

示例12: shift

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/** Copy file.content[from...f.length-1] into file.content[to...], then truncate the file after that point.
 * <p> If (from &gt; to), this means we simply delete the portion of the file beginning at "to" and up to but excluding "from".
 * <p> If (from &lt; to), this means we insert (to-from) number of ARBITRARY bytes into the "from" location
 *     and shift the original file content accordingly.
 * <p> Note: after this operation, the file's current position will be moved to the start of the file.
 * @throws IOException if (from &lt; 0) || (to &lt; 0) || (from &gt;= file.length())
 */
public static void shift (RandomAccessFile file, long from, long to) throws IOException {
   long total = file.length();
   if (from<0 || from>=total || to<0) throw new IOException(); else if (from==to) {file.seek(0); return;}
   final byte buf[] = new byte[4096];
   int res;
   if (from>to) {
      while(true) {
         file.seek(from);
         if ((res=file.read(buf)) <= 0) { file.setLength(to); file.seek(0); return; }
         file.seek(to); file.write(buf, 0, res); from=from+res; to=to+res;
      }
   } else {
      file.seek(total);
      for(long todo=to-from; todo>0;) {
         if (todo >= buf.length) {file.write(buf); todo = todo - buf.length;} else {file.write(buf, 0, (int)todo); break;}
      }
      for(long todo=total-from; todo>0; total=total-res, todo=todo-res) {
         if (todo > buf.length) res=buf.length; else res=(int)todo;
         file.seek(total - res);
         for(int done=0; done<res;) { int r=file.read(buf, done, res-done); if (r<=0) throw new IOException(); else done += r; }
         file.seek(total - res + (to - from));
         file.write(buf, 0, res);
      }
   }
   file.seek(0);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:34,代码来源:Util.java

示例13: readWordIndex

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private int readWordIndex(RandomAccessFile raf) throws IOException {
	String word = readWord(raf);
	if(raf.length()==raf.getFilePointer()) {
		return -1;
	}
	return searchVocab(word);
}
 
开发者ID:taki0112,项目名称:Naver-Keyword_Analysis,代码行数:8,代码来源:Word2Vec.java

示例14: deserialize

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Read the inflights file and return a
 * {@link com.google.common.collect.SetMultimap}
 * of transactionIDs to events that were inflight.
 *
 * @return - map of inflight events per txnID.
 */
public SetMultimap<Long, Long> deserialize()
    throws IOException, BadCheckpointException {
  SetMultimap<Long, Long> inflights = HashMultimap.create();
  if (!fileChannel.isOpen()) {
    file = new RandomAccessFile(inflightEventsFile, "rw");
    fileChannel = file.getChannel();
  }
  if (file.length() == 0) {
    return inflights;
  }
  file.seek(0);
  byte[] checksum = new byte[16];
  file.read(checksum);
  ByteBuffer buffer = ByteBuffer.allocate(
      (int) (file.length() - file.getFilePointer()));
  fileChannel.read(buffer);
  byte[] fileChecksum = digest.digest(buffer.array());
  if (!Arrays.equals(checksum, fileChecksum)) {
    throw new BadCheckpointException("Checksum of inflights file differs"
        + " from the checksum expected.");
  }
  buffer.position(0);
  LongBuffer longBuffer = buffer.asLongBuffer();
  try {
    while (true) {
      long txnID = longBuffer.get();
      int numEvents = (int) (longBuffer.get());
      for (int i = 0; i < numEvents; i++) {
        long val = longBuffer.get();
        inflights.put(txnID, val);
      }
    }
  } catch (BufferUnderflowException ex) {
    LOG.debug("Reached end of inflights buffer. Long buffer position ="
        + String.valueOf(longBuffer.position()));
  }
  return inflights;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:46,代码来源:FlumeEventQueue.java

示例15: readBytesFromFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * @param filePath The path relative to
 * {@link com.google.testing.util.TestUtil#getDefaultSrcDir}.
 */
public static ByteString readBytesFromFile(String filename) {
  File fullPath = new File(getTestDataDir(), filename);
  try {
    RandomAccessFile file = new RandomAccessFile(fullPath, "r");
    byte[] content = new byte[(int) file.length()];
    file.readFully(content);
    return ByteString.copyFrom(content);
  } catch (IOException e) {
    // Throw a RuntimeException here so that we can call this function from
    // static initializers.
    throw new IllegalArgumentException(
      "Couldn't read file: " + fullPath.getPath(), e);
  }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:19,代码来源:TestUtil.java


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