Package java.nio.channels

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


        FileOutputStream fos = new FileOutputStream(out);
       
        FileChannel readableChannel = fis.getChannel();
        FileChannel writableChannel = fos.getChannel();
       
        writableChannel.truncate(0);
        writableChannel.transferFrom(readableChannel, 0, readableChannel.size());
        fis.close();
        fos.close();
        return true;
      }
View Full Code Here


      FileOutputStream outputStream = new FileOutputStream(targetFile);

      FileChannel readableChannel = inputStream.getChannel();
      FileChannel writableChannel = outputStream.getChannel();

      writableChannel.truncate(0);
      writableChannel.transferFrom(
        readableChannel, 0, readableChannel.size());
      inputStream.close();
      outputStream.close();
    } catch (IOException ioException) {
View Full Code Here

      FileOutputStream outputStream = new FileOutputStream(targetFile);

      FileChannel readableChannel = inputStream.getChannel();
      FileChannel writableChannel = outputStream.getChannel();

      writableChannel.truncate(0);
      writableChannel.transferFrom(
        readableChannel, 0, readableChannel.size());
      inputStream.close();
      outputStream.close();
    } catch (IOException ioException) {
View Full Code Here

    FileChannel outChan;
    try {
      outChan = new FileOutputStream(
          new File(IConstants.CITY_CONFIG_FILE), true).getChannel();

      outChan.truncate(0);
      outChan.close();

    } catch (FileNotFoundException e) {
      log.error(e, e);
      return;
View Full Code Here

        FileUtils.createDirectories(getBaseDir() + "/fs");
        FileChannel c = FileUtils.open(f, "rw");
        c.position(4000);
        c.write(ByteBuffer.wrap(new byte[1]));
        FileLock lock = c.tryLock();
        c.truncate(0);
        if (lock != null) {
            lock.release();
        }
        c.close();
    }
View Full Code Here

                    ra.write(buffer, 0, buffer.length);
                    break;
                }
                case 2: {
                    trace("truncate " + pos);
                    f.truncate(pos);
                    if (pos < ra.length()) {
                        // truncate is supposed to have no effect if the
                        // position is larger than the current size
                        ra.setLength(pos);
                    }
View Full Code Here

            target.createNewFile();
        } else if (endpoint.getFileExist() == GenericFileExist.Override) {
            LOG.debug("Truncating existing file: {}", target);
            FileChannel out = new FileOutputStream(target).getChannel();
            try {
                out.truncate(0);
            } finally {
                IOHelper.force(out, target.getName(), LOG);
                IOHelper.close(out, target.getName(), LOG);
            }
        }
View Full Code Here

            Object value = attributes.get(attribute);
            switch (attribute) {
                case Size:             {
                    long newSize = (Long) value;
                    FileChannel outChan = new FileOutputStream(file, true).getChannel();
                    outChan.truncate(newSize);
                    outChan.close();
                    continue;
                }
                case Uid:              name = "unix:uid"; break;
                case Owner:            name = "unix:owner"; value = toUser((String) value); break;
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));
            fileChannel.position(position);
        } else {
            fileChannel.truncate(newLength);
        }
    }

    /**
     * Invalidate buffer before a position change has occurred (e.g. seek),
View Full Code Here

            leftSize = r.nextInt(headerLen);
        } else {
            leftSize = headerLen + r.nextInt(1024 - headerLen);
        }
        FileChannel fc = new RandomAccessFile(fn, "rw").getChannel();
        fc.truncate(leftSize);
        fc.close();
    }

    /**
     * Generate meta entry with given master key
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.