Package java.nio.channels

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


            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


            else
                args.put("latest_time", lastTime);
                addEndOfLine = true;

            FileChannel fc = raf.getChannel();
            fc.truncate(fptrEof);
        } else
        if (!file.createNewFile())
            throw new Error("Failed to create output file");

        // Search args
View Full Code Here

            FileUtil.createNewFile(target);
        } else if (endpoint.getFileExist() == GenericFileExist.Override) {
            LOG.debug("Truncating existing file: {}", target);
            FileChannel out = new FileOutputStream(target).getChannel();
            try {
                out.truncate(0);
            } finally {
                IOHelper.close(out, target.getName(), LOG, endpoint.isForceWrites());
            }
        }
    }
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 LastModifiedTime:
                setLastModified((Long) value);
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 Gid:              name = "unix:gid"; break;
View Full Code Here

          FileOutputStream s = null;
          FileChannel channel = null;
          try {
            s = new FileOutputStream(f);
            channel = s.getChannel();
            channel.truncate(0);
            LOG.info("Truncated block file " + f.getAbsolutePath());
            return b.getBlockId();
          } finally {
            IOUtils.cleanup(LOG, channel, s);
          }
View Full Code Here

    // binary, XML, reparsed binary
    String edits = nnHelper.generateEdits();
    FileOutputStream os = new FileOutputStream(edits, true);
    // Corrupt the file by truncating the end
    FileChannel editsFile = os.getChannel();
    editsFile.truncate(editsFile.size() - 5);

    String editsParsedXml = folder.newFile("editsRecoveredParsed.xml")
        .getAbsolutePath();
    String editsReparsed = folder.newFile("editsRecoveredReparsed")
        .getAbsolutePath();
View Full Code Here

            FileUtil.createNewFile(target);
        } else if (endpoint.getFileExist() == GenericFileExist.Override) {
            LOG.debug("Truncating existing file: {}", target);
            FileChannel out = new FileOutputStream(target).getChannel();
            try {
                out.truncate(0);
            } finally {
                IOHelper.close(out, target.getName(), LOG, endpoint.isForceWrites());
            }
        }
    }
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

                long currentSize = channel.size();
                channel.position(0);
                channel.write(ByteBuffer.wrap(baos.toByteArray()));
                if (currentSize > baos.size())
                {
                    channel.truncate(baos.size());
                }
            }
            catch (IOException e)
            {
                throw new IllegalConfigurationException("Cannot store preferences", e);
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.