Package java.nio.channels

Examples of java.nio.channels.FileChannel.truncate()


          java.io.File fileData = new java.io.File(tempUserFolder.getAbsolutePath() + java.io.File.separator + fileName);
          if(fileData.exists())
            fileData.delete();
          // Saving the new working data
          FileChannel writeCurrentChannel = new FileOutputStream(fileData).getChannel();
          writeCurrentChannel.truncate(0);
          ByteBuffer buffer = ByteBuffer.allocate(currentData.length);
          buffer.put(currentData);
          buffer.position(0);
          writeCurrentChannel.write(buffer);
          writeCurrentChannel.force(false);
View Full Code Here


              if(fileData.exists())
                fileData.delete();
            }
          // Saving the new working data
          FileChannel writeCurrentChannel = new FileOutputStream(fileData).getChannel();
          writeCurrentChannel.truncate(0);
          ByteBuffer buffer = ByteBuffer.allocate(currentData.length);
          buffer.put(currentData);
          buffer.position(0);
          writeCurrentChannel.write(buffer);
          writeCurrentChannel.force(false);
View Full Code Here

            FileChannel channel = file.getChannel();
            int newsize = random.nextInt((int)channel.size()/2);
            System.out.println("Deliberately truncating file " +
                               blocks[idx].getName() +
                               " to size " + newsize + " bytes.");
            channel.truncate(newsize);
            file.close();
          } else {
            //
            // corrupt a few bytes of the metafile
            //
View Full Code Here

    // binary, XML, reparsed binary
    String edits          = nnHelper.generateEdits();
   
    // Corrupt the file by truncating the end
    FileChannel editsFile = new FileOutputStream(edits, true).getChannel();
    editsFile.truncate(editsFile.size() - 5);
   
    String editsParsedXml = cacheDir + "/editsRecoveredParsed.xml";
    String editsReparsed  = cacheDir + "/editsRecoveredReparsed";
    String editsParsedXml2 = cacheDir + "/editsRecoveredParsed2.xml";
View Full Code Here

        File mf = b.getMetaFile();
        // Truncate a block file that has a corresponding metadata file
        if (f.exists() && f.length() != 0 && mf.exists()) {
          FileOutputStream s = new FileOutputStream(f);
          FileChannel channel = s.getChannel();
          channel.truncate(0);
          LOG.info("Truncated block file " + f.getAbsolutePath());
          return b.getBlockId();
        }
      }
    }
View Full Code Here

        RandomAccessFile raFile = new RandomAccessFile((File)args[1], "rw");
        try {
          FileChannel channel = raFile.getChannel();
          long filesize = channel.size();
          assertFalse(0 == filesize);
          channel.truncate(filesize-1);
        } finally {
          raFile.close();
        }
      } else { // HDFS: decrement last block size
        assertTrue(args[0] instanceof DistributedFileSystem);
View Full Code Here

 
  private void truncateFile(File f) throws IOException {
    assertTrue(f.exists() && f.length() != 0);
    FileOutputStream s = new FileOutputStream(f);
    FileChannel channel = s.getChannel();
    channel.truncate(0);
    LOG.info("Truncated block file " + f.getAbsolutePath());
    s.close();
  }
 
  public ScanChecker checker() {
View Full Code Here

        File mf = BlockWithChecksumFileWriter.getMetaFile(f, b.getBlock());
        // Truncate a block file that has a corresponding metadata file
        if (f.exists() && f.length() != 0 && mf.exists()) {
          FileOutputStream s = new FileOutputStream(f);
          FileChannel channel = s.getChannel();
          channel.truncate(0);
          LOG.info("Truncated block file " + f.getAbsolutePath());
          long blockId = b.getBlock().getBlockId();
          s.close();
          return blockId;
        }
View Full Code Here

            FileChannel channel = file.getChannel();
            int newsize = random.nextInt((int)channel.size()/2);
            System.out.println("Deliberately truncating file " +
                               blocks[idx].getName() +
                               " to size " + newsize + " bytes.");
            channel.truncate(newsize);
            file.close();
          } else {
            //
            // corrupt a few bytes of the metafile
            //
View Full Code Here

        if (!this.file.exists()) {
            this.file.createNewFile();
        }

        final FileChannel channel = new RandomAccessFile(this.file, "rw").getChannel();
        channel.truncate(0);
        this.fileMessageSet = new FileMessageSet(channel);
    }


    @After
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.