Package java.nio.channels

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


        else
            value--;
        bb.position(pos);
        bb.put(value);
        bb.force();
        fc.truncate(len);
        fc.close();
        return value & 0xFF;
    }
   
   
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

            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

        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

            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

        } catch (IOException ioe) {
            throw new ResourceException.IOError(ioe);
        }

        try {
            if (flags.isTruncate()) fileChannel.truncate(0);
        } catch (IOException ioe) {
            // ignore; it's a pipe or fifo that can't be truncated (we only care about illegal seek).
            if (!ioe.getMessage().equals("Illegal seek")) throw new ResourceException.IOError(ioe);
        }
View Full Code Here

            fileChannel.position(fileChannel.size());
            // FIXME: This worries me a bit, since it could allocate a lot with a large newLength
            fileChannel.write(ByteBuffer.allocate(difference));
        } else {
            fileChannel.truncate(newLength);
        }
        fileChannel.position(position);
    }

    /**
 
View Full Code Here

  }

  private void write_data(ByteString bytes) throws IOException {
    FileChannel ch = file.getChannel();
    if (is_write_lock) {
      ch.truncate(0);
      ch.write(bytes.asReadOnlyByteBuffer(), 0);

      return;
    }
View Full Code Here

        byte value = bb.get(pos);
        value--;
        bb.position(pos);
        bb.put(value);
        bb.force();
        fc.truncate(len);
        fc.close();
        return value & 0xFF;
    }
 
    /*
 
View Full Code Here

        else
            value--;
        bb.position(pos);
        bb.put(value);
        bb.force();
        fc.truncate(len);
        fc.close();
        return value & 0xFF;
    }
   
   
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.