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


Java RandomAccessFile.seek方法代码示例

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


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

示例1: preloadLineTile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
 public void preloadLineTile(int y, int length,int band) {
     if (y < 0) {
         return;
     }
     preloadedInterval = new int[]{y, y + length};
     //positioning in file images y=rows image.xSize=cols 4=numero bytes 
     int tileOffset =  (y * (getImage(band).getxSize() * 4 ));
     preloadedData = new byte[(getImage(band).getxSize() * 4) * length];
     try {
     	File fimg = getImage(band).getImageFile();
fss = new RandomAccessFile(fimg.getAbsolutePath(), "r");
fss.seek(tileOffset);
        	fss.read(preloadedData);
     } catch (IOException ex) {
     	logger.error(ex.getMessage(),ex);
     }finally{
     	try {
	fss.close();
} catch (IOException e) {
	logger.warn(e.getMessage());
}
     }
 }
 
开发者ID:ec-europa,项目名称:sumo,代码行数:25,代码来源:Sentinel1SLCDebursted.java

示例2: readState

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public LockState readState(RandomAccessFile lockFileAccess) throws IOException {
    try {
        byte[] buffer = new byte[stateRegionSize];
        lockFileAccess.seek(REGION_START);

        int readPos = 0;
        while (readPos < buffer.length) {
            int nread = lockFileAccess.read(buffer, readPos, buffer.length - readPos);
            if (nread < 0) {
                break;
            }
            readPos += nread;
        }

        ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, 0, readPos);
        DataInputStream dataInput = new DataInputStream(inputStream);

        byte protocolVersion = dataInput.readByte();
        if (protocolVersion != protocol.getVersion()) {
            throw new IllegalStateException(String.format("Unexpected lock protocol found in lock file. Expected %s, found %s.", protocol.getVersion(), protocolVersion));
        }
        return protocol.read(dataInput);
    } catch (EOFException e) {
        return protocol.createInitialState();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:27,代码来源:LockStateAccess.java

示例3: shortSummarizeOggPageHeaders

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Summarizes the first five pages, normally all we are interested in
 *
 * @param oggFile
 * @throws CannotReadException
 * @throws IOException
 */
public void shortSummarizeOggPageHeaders(File oggFile) throws CannotReadException, IOException {
    RandomAccessFile raf = new RandomAccessFile(oggFile, "r");

    int i = 0;
    while (raf.getFilePointer() < raf.length()) {
        System.out.println("pageHeader starts at absolute file position:" + raf.getFilePointer());
        OggPageHeader pageHeader = OggPageHeader.read(raf);
        System.out.println("pageHeader finishes at absolute file position:" + raf.getFilePointer());
        System.out.println(pageHeader + "\n");
        raf.seek(raf.getFilePointer() + pageHeader.getPageLength());
        i++;
        if (i >= 5) {
            break;
        }
    }
    System.out.println("Raf File Pointer at:" + raf.getFilePointer() + "File Size is:" + raf.length());
    raf.close();
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:26,代码来源:OggFileReader.java

示例4: setOffsetFromFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void setOffsetFromFile(RandomAccessFile f, ByteBuffer buf) throws IOException {
    long localHdrOffset = mLocalHdrOffset;
    try {
        f.seek(localHdrOffset);
        f.readFully(buf.array());
        if (buf.getInt(0) != kLFHSignature) {
            Log.w(LOG_TAG, "didn't find signature at start of lfh");
            throw new IOException();
        }
        int nameLen = buf.getShort(kLFHNameLen) & 0xFFFF;
        int extraLen = buf.getShort(kLFHExtraLen) & 0xFFFF;
        mOffset = localHdrOffset + kLFHLen + nameLen + extraLen;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:19,代码来源:ZipResourceFile.java

示例5: revertBuffer

import java.io.RandomAccessFile; //导入方法依赖的package包/类
LongBuffer revertBuffer() throws IOException {
    LongBuffer reverted = new LongBuffer(buffer.length);
    
    if (bufferSize < buffer.length) {
        for (int i=0;i<bufferSize;i++) {
            reverted.writeLong(buffer[bufferSize - 1 - i]);
        }
    } else {
        writeStream.flush();
        RandomAccessFile raf = new RandomAccessFile(backingFile,"r");
        long offset = raf.length();
        while(offset > 0) {
            offset-=8;
            raf.seek(offset);
            reverted.writeLong(raf.readLong());
        }
    }
    reverted.startReading();
    return reverted;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:LongBuffer.java

示例6: open

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public long open(DataSpec dataSpec) throws FileDataSourceException {
  try {
    uriString = dataSpec.uri.toString();
    file = new RandomAccessFile(dataSpec.uri.getPath(), "r");
    file.seek(dataSpec.position);
    bytesRemaining = dataSpec.length == C.LENGTH_UNBOUNDED ? 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();
  }

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

示例7: isValidSnapshot

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Verifies that the file is a valid snapshot. Snapshot may be invalid if 
 * it's incomplete as in a situation when the server dies while in the process
 * of storing a snapshot. Any file that is not a snapshot is also 
 * an invalid snapshot. 
 * 
 * @param f file to verify
 * @return true if the snapshot is valid
 * @throws IOException
 */
public static boolean isValidSnapshot(File f) throws IOException {
    if (f==null || Util.getZxidFromName(f.getName(), "snapshot") == -1)
        return false;

    // Check for a valid snapshot
    RandomAccessFile raf = new RandomAccessFile(f, "r");
    try {
        // including the header and the last / bytes
        // the snapshot should be atleast 10 bytes
        if (raf.length() < 10) {
            return false;
        }
        raf.seek(raf.length() - 5);
        byte bytes[] = new byte[5];
        int readlen = 0;
        int l;
        while(readlen < 5 &&
              (l = raf.read(bytes, readlen, bytes.length - readlen)) >= 0) {
            readlen += l;
        }
        if (readlen != bytes.length) {
            LOG.info("Invalid snapshot " + f
                    + " too short, len = " + readlen);
            return false;
        }
        ByteBuffer bb = ByteBuffer.wrap(bytes);
        int len = bb.getInt();
        byte b = bb.get();
        if (len != 1 || b != '/') {
            LOG.info("Invalid snapshot " + f + " len = " + len
                    + " byte = " + (b & 0xff));
            return false;
        }
    } finally {
        raf.close();
    }

    return true;
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:50,代码来源:Util.java

示例8: copy

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private int copy(InputStream in, RandomAccessFile out) throws IOException, UpdateError {

        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedInputStream bis = new BufferedInputStream(in, BUFFER_SIZE);
        try {

            out.seek(out.length());

            int bytes = 0;
            long previousBlockTime = -1;

            while (!isCancelled()) {
                int n = bis.read(buffer, 0, BUFFER_SIZE);
                if (n == -1) {
                    break;
                }
                out.write(buffer, 0, n);
                bytes += n;

                checkNetwork();

                if (mSpeed != 0) {
                    previousBlockTime = -1;
                } else if (previousBlockTime == -1) {
                    previousBlockTime = System.currentTimeMillis();
                } else if ((System.currentTimeMillis() - previousBlockTime) > TIME_OUT) {
                    throw new UpdateError(UpdateError.DOWNLOAD_NETWORK_TIMEOUT);
                }
            }
            return bytes;
        } finally {
            out.close();
            bis.close();
            in.close();
        }
    }
 
开发者ID:yufeilong92,项目名称:update-master,代码行数:37,代码来源:UpdateDownloader.java

示例9: readByte

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private int readByte( final RandomAccessFile file, final long position )
{
    try
    {
        file.seek( position );
        return file.readByte();
    }
    catch ( IOException e )
    {
        return -1;
    }
}
 
开发者ID:aro,项目名称:app-logbrowser,代码行数:13,代码来源:LogFileHandler.java

示例10: readLockInfo

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public LockInfo readLockInfo(RandomAccessFile lockFileAccess) throws IOException {
    if (lockFileAccess.length() <= infoRegionPos) {
        return new LockInfo();
    } else {
        lockFileAccess.seek(infoRegionPos);

        DataInputStream inputStream = new DataInputStream(new BufferedInputStream(new RandomAccessFileInputStream(lockFileAccess)));
        byte protocolVersion = inputStream.readByte();
        if (protocolVersion != lockInfoSerializer.getVersion()) {
            throw new IllegalStateException(String.format("Unexpected lock protocol found in lock file. Expected %s, found %s.", lockInfoSerializer.getVersion(), protocolVersion));
        }

        return lockInfoSerializer.read(inputStream);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:LockInfoAccess.java

示例11: doTestBadCheckpointVersion

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void doTestBadCheckpointVersion(boolean backup) throws Exception {
  Map<String, String> overrides = Maps.newHashMap();
  overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Set<String> in = putEvents(channel, "restart", 10, 100);
  Assert.assertEquals(100, in.size());
  forceCheckpoint(channel);
  if (backup) {
    Thread.sleep(2000);
  }
  channel.stop();
  File checkpoint = new File(checkpointDir, "checkpoint");
  RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
  writer.seek(EventQueueBackingStoreFile.INDEX_VERSION *
              Serialization.SIZE_OF_LONG);
  writer.writeLong(2L);
  writer.getFD().sync();
  writer.close();
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Assert.assertTrue(!backup || channel.checkpointBackupRestored());
  Set<String> out = consumeChannel(channel);
  compareInputAndOut(in, out);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:28,代码来源:TestFileChannelRestart.java

示例12: testValidateEditLogWithCorruptHeader

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Test
public void testValidateEditLogWithCorruptHeader() throws IOException {
  File testDir = new File(TEST_DIR, "testValidateEditLogWithCorruptHeader");
  SortedMap<Long, Long> offsetToTxId = Maps.newTreeMap();
  File logFile = prepareUnfinalizedTestEditLog(testDir, 2, offsetToTxId);
  RandomAccessFile rwf = new RandomAccessFile(logFile, "rw");
  try {
    rwf.seek(0);
    rwf.writeLong(42); // corrupt header
  } finally {
    rwf.close();
  }
  EditLogValidation validation = EditLogFileInputStream.validateEditLog(logFile);
  assertTrue(validation.hasCorruptHeader());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:TestFSEditLogLoader.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: testWriteFully

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Test
public void testWriteFully() throws IOException {
  final int INPUT_BUFFER_LEN = 10000;
  final int HALFWAY = 1 + (INPUT_BUFFER_LEN / 2);
  byte[] input = new byte[INPUT_BUFFER_LEN];
  for (int i = 0; i < input.length; i++) {
    input[i] = (byte)(i & 0xff);
  }
  byte[] output = new byte[input.length];
  
  try {
    RandomAccessFile raf = new RandomAccessFile(TEST_FILE_NAME, "rw");
    FileChannel fc = raf.getChannel();
    ByteBuffer buf = ByteBuffer.wrap(input);
    IOUtils.writeFully(fc, buf);
    raf.seek(0);
    raf.read(output);
    for (int i = 0; i < input.length; i++) {
      assertEquals(input[i], output[i]);
    }
    buf.rewind();
    IOUtils.writeFully(fc, buf, HALFWAY);
    for (int i = 0; i < HALFWAY; i++) {
      assertEquals(input[i], output[i]);
    }
    raf.seek(0);
    raf.read(output);
    for (int i = HALFWAY; i < input.length; i++) {
      assertEquals(input[i - HALFWAY], output[i]);
    }
  } finally {
    File f = new File(TEST_FILE_NAME);
    if (f.exists()) {
      f.delete();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:38,代码来源:TestIOUtils.java

示例15: createInputStream

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public InputStream createInputStream (long offset) throws IOException
{
   File file = new File(product.getDownloadablePath());
   if (!doesExist())
   {
       throw new IOException("No read permission : " + file.getName());
   }

   // move to the appropriate offset and create input stream
   final RandomAccessFile raf = new RandomAccessFile(file, "r");
   try
   {
      raf.seek(offset);
      // The IBM jre needs to have both the stream and the random access file
      // objects closed to actually close the file
      return new RegulatedInputStream.Builder (new FileInputStream (
            raf.getFD())
      {
         public void close() throws IOException
         {
            super.close();
            raf.close();
         }
      }, TrafficDirection.OUTBOUND).userName(super.user.getUsername ()).
      copyStreamListener (
            new DownloadActionRecordListener (
         product.getUuid(), product.getIdentifier(), super.user)).
         streamSize(raf.length()).build ();
   }
   catch (IOException e)
   {
      raf.close();
      throw e;
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:37,代码来源:FtpProductFile.java


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