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


Java RandomAccessFile.close方法代码示例

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


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

示例1: countMetaBlocks

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Count the number of metadatablocks, useful for debugging
 *
 * @param f
 * @return
 * @throws CannotReadException
 * @throws IOException
 */
public int countMetaBlocks(File f) throws CannotReadException, IOException {
    RandomAccessFile raf = new RandomAccessFile(f, "r");
    FlacStreamReader flacStream = new FlacStreamReader(raf);
    flacStream.findStream();


    boolean isLastBlock = false;

    int count = 0;
    while (!isLastBlock) {
        MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
        logger.config("Found block:" + mbh.getBlockType());
        raf.seek(raf.getFilePointer() + mbh.getDataLength());
        isLastBlock = mbh.isLastBlock();
        mbh = null; //Free memory
        count++;
    }
    raf.close();
    return count;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:29,代码来源:FlacInfoReader.java

示例2: testCorruptCheckpointCompleteMarkerMostSignificant4Bytes

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Test
public void testCorruptCheckpointCompleteMarkerMostSignificant4Bytes() throws Exception {
  Map<String, String> overrides = Maps.newHashMap();
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Set<String> in = putEvents(channel, "restart", 10, 100);
  Assert.assertEquals(100, in.size());
  forceCheckpoint(channel);
  channel.stop();
  File checkpoint = new File(checkpointDir, "checkpoint");
  RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
  writer.seek(EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER *
              Serialization.SIZE_OF_LONG);
  writer.write(new byte[] { (byte) 1, (byte) 5 });
  writer.getFD().sync();
  writer.close();
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Set<String> out = consumeChannel(channel);
  Assert.assertTrue(channel.didFullReplayDueToBadCheckpointException());
  compareInputAndOut(in, out);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:TestFileChannelRestart.java

示例3: testCorruptCheckpointVersionMostSignificant4Bytes

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Test
public void testCorruptCheckpointVersionMostSignificant4Bytes() throws Exception {
  Map<String, String> overrides = Maps.newHashMap();
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Set<String> in = putEvents(channel, "restart", 10, 100);
  Assert.assertEquals(100, in.size());
  forceCheckpoint(channel);
  channel.stop();
  File checkpoint = new File(checkpointDir, "checkpoint");
  RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
  writer.seek(EventQueueBackingStoreFile.INDEX_VERSION *
              Serialization.SIZE_OF_LONG);
  writer.write(new byte[] { (byte) 1, (byte) 5 });
  writer.getFD().sync();
  writer.close();
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Set<String> out = consumeChannel(channel);
  Assert.assertTrue(channel.didFullReplayDueToBadCheckpointException());
  compareInputAndOut(in, out);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:TestFileChannelRestart.java

示例4: writeTxtToFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
public void writeTxtToFile(String strcontent, String filePath, String fileName) {
    // �����ļ���֮���������ļ�����Ȼ�����
    makeFilePath(filePath, fileName);
	 
    String strFilePath = filePath + fileName;
    // ÿ��д��ʱ��������д
    String strContent = strcontent + "\r\n";
    try {
        File file = new File(strFilePath);
        if (!file.exists()) {
            Log.d("TestFile", "Create the file:" + strFilePath);
            file.getParentFile().mkdirs();
            file.createNewFile();
        }
        RandomAccessFile raf = new RandomAccessFile(file, "rwd");
        raf.seek(file.length());
        raf.write(strContent.getBytes());
        raf.close();
	 
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Edward7Zhang,项目名称:oneKey2Alarm,代码行数:24,代码来源:aid.java

示例5: FileNioMapped

import java.io.RandomAccessFile; //导入方法依赖的package包/类
FileNioMapped(String fileName, String mode) throws IOException {
    if ("r".equals(mode)) {
        this.mode = MapMode.READ_ONLY;
    } else {
        this.mode = MapMode.READ_WRITE;
    }
    this.name = fileName;
    file = new RandomAccessFile(fileName, mode);
    try {
        reMap();
    } catch (IOException e) {
        if (file != null) {
            file.close();
            file = null;
        }
        throw e;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:19,代码来源:FileNioMapped.java

示例6: uploadFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**  
 * �ϴ��ļ���������,���ϴ��Ͷϵ�����  
 * @param remoteFile Զ���ļ��������ϴ�֮ǰ�Ѿ�������������Ŀ¼���˸ı�  
 * @param localFile �����ļ� File���������·��  
 * @param processStep ��Ҫ��ʾ�Ĵ�����Ȳ���ֵ  
 * @param ftpClient FTPClient ����  
 * @return  
 * @throws IOException  
 */  
public UploadStatus uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{   
    UploadStatus status;   
    //��ʾ���ȵ��ϴ�   
    long step = localFile.length() / 100;   
    long process = 0;   
    long localreadbytes = 0L;   
    RandomAccessFile raf = new RandomAccessFile(localFile,"r");   
    OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"),"iso-8859-1")); 
    //�ϵ�����   
    if(remoteSize>0){   
        ftpClient.setRestartOffset(remoteSize);   
        process = remoteSize /step;   
        raf.seek(remoteSize);   
        localreadbytes = remoteSize;   
    }   
    byte[] bytes = new byte[1024];   
    int c;   
    while((c = raf.read(bytes))!= -1){   
        out.write(bytes,0,c);   
        localreadbytes+=c;   
        if(localreadbytes / step != process){   
            process = localreadbytes / step;   
            System.out.println("�ϴ�����:" + process);   
            //TODO �㱨�ϴ�״̬   
        }   
    }   
    out.flush();   
    raf.close();   
    out.close();   
    boolean result =ftpClient.completePendingCommand();   
    if(remoteSize > 0){   
        status = result?UploadStatus.Upload_From_Break_Success:UploadStatus.Upload_From_Break_Failed;   
    }else {   
        status = result?UploadStatus.Upload_New_File_Success:UploadStatus.Upload_New_File_Failed;   
    }   
    return status;   
}
 
开发者ID:cai784921129,项目名称:FTP,代码行数:47,代码来源:ContinueFTP.java

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

示例8: corruptFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * corrupt a file by writing m at 500 b
 * offset
 * @param file the file to be corrupted
 * @throws IOException
 */
private void corruptFile(File file) throws IOException {
    // corrupt the logfile
    RandomAccessFile raf  = new RandomAccessFile(file, "rw");
    byte[] b = "mahadev".getBytes();
    long writeLen = 500L;
    raf.seek(writeLen);
    //corrupting the data
    raf.write(b);
    raf.close();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:17,代码来源:CRCTest.java

示例9: onCloseRandomAccessFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void onCloseRandomAccessFile(RandomAccessFile rafFile) {
    try {
        if (rafFile != null) {
            rafFile.close();
        }
    } catch (Exception e) {

    }
}
 
开发者ID:CodingCodersCode,项目名称:EvolvingNetLib,代码行数:10,代码来源:CCDownloadRequest.java

示例10: createRandomFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private static Path createRandomFile(long size) throws IOException {
  Path path = Paths.get("/tmp/" + UUID.randomUUID().toString() + ".txt");
  RandomAccessFile file = new RandomAccessFile(path.toString(), "rw");
  file.writeChars("test content\n");
  file.setLength(size);
  file.close();
  return path;
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:9,代码来源:TestClient.java

示例11: fillZipWithContent

import java.io.RandomAccessFile; //导入方法依赖的package包/类
private void fillZipWithContent() throws IOException {
    RandomAccessFile raf = new RandomAccessFile(txtFile,"rw");
    raf.writeUTF("Test");
    raf.close();
    try (FileOutputStream fos = new FileOutputStream(zipFile)) {
        try (ZipOutputStream zos = new ZipOutputStream(fos)) {
            try (FileInputStream fis = new FileInputStream(txtFile)) {
                ZipEntry zipEntry = new ZipEntry("test.txt");
                zos.putNextEntry(zipEntry);
                byte[] bytes = new byte[1024];
                int length;
                while ((length = fis.read(bytes)) >= 0) {
                    zos.write(bytes, 0, length);
                }
                zos.flush();
                zos.closeEntry();
                fos.flush();
            }
        }
    }
    zipFile.deleteOnExit();
    txtFile.deleteOnExit();
}
 
开发者ID:e-Spirit,项目名称:FSTestTools,代码行数:24,代码来源:ZipImportCommandsTest.java

示例12: 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:zhanghangyes,项目名称:updateUtils,代码行数:37,代码来源:UpdateDownloader.java

示例13: checkAndSetUploadProgress

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * 检查并修改文件上传进度
 *
 * @param param
 * @param uploadDirPath
 * @return
 * @throws IOException
 */
private boolean checkAndSetUploadProgress(MultipartFileParam param, String uploadDirPath) throws IOException {
    String fileName = param.getName();
    File confFile = new File(uploadDirPath, fileName + ".conf");
    RandomAccessFile accessConfFile = new RandomAccessFile(confFile, "rw");
    //把该分段标记为 true 表示完成
    System.out.println("set part " + param.getChunk() + " complete");
    accessConfFile.setLength(param.getChunks());
    accessConfFile.seek(param.getChunk());
    accessConfFile.write(Byte.MAX_VALUE);

    //completeList 检查是否全部完成,如果数组里是否全部都是(全部分片都成功上传)
    byte[] completeList = FileUtils.readFileToByteArray(confFile);
    byte isComplete = Byte.MAX_VALUE;
    for (int i = 0; i < completeList.length && isComplete == Byte.MAX_VALUE; i++) {
        //与运算, 如果有部分没有完成则 isComplete 不是 Byte.MAX_VALUE
        isComplete = (byte) (isComplete & completeList[i]);
        System.out.println("check part " + i + " complete?:" + completeList[i]);
    }

    accessConfFile.close();
    if (isComplete == Byte.MAX_VALUE) {
        stringRedisTemplate.opsForHash().put(Constants.FILE_UPLOAD_STATUS, param.getMd5(), "true");
        stringRedisTemplate.opsForValue().set(Constants.FILE_MD5_KEY + param.getMd5(), uploadDirPath + "/" + fileName);
        return true;
    } else {
        if (!stringRedisTemplate.opsForHash().hasKey(Constants.FILE_UPLOAD_STATUS, param.getMd5())) {
            stringRedisTemplate.opsForHash().put(Constants.FILE_UPLOAD_STATUS, param.getMd5(), "false");
        }
        if (stringRedisTemplate.hasKey(Constants.FILE_MD5_KEY + param.getMd5())) {
            stringRedisTemplate.opsForValue().set(Constants.FILE_MD5_KEY + param.getMd5(), uploadDirPath + "/" + fileName + ".conf");
        }
        return false;
    }
}
 
开发者ID:Fourwenwen,项目名称:Breakpoint-http,代码行数:43,代码来源:StorageServiceImpl.java

示例14: corrupt

import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public void corrupt(File editFile) throws IOException {
  // Add junk to the end of the file
  RandomAccessFile rwf = new RandomAccessFile(editFile, "rw");
  rwf.seek(editFile.length());
  rwf.write((byte)-1);
  for (int i = 0; i < 1024; i++) {
    rwf.write(padByte);
  }
  rwf.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:TestNameNodeRecovery.java

示例15: setFromFile

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Create Artwork from File
 *
 * @param file
 * @throws java.io.IOException
 */
public void setFromFile(File file) throws IOException {
    RandomAccessFile imageFile = new RandomAccessFile(file, "r");
    byte[] imagedata = new byte[(int) imageFile.length()];
    imageFile.read(imagedata);
    imageFile.close();

    setBinaryData(imagedata);
    setMimeType(ImageFormats.getMimeTypeForBinarySignature(imagedata));
    setDescription("");
    setPictureType(PictureTypes.DEFAULT_ID);
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:18,代码来源:StandardArtwork.java


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