Package java.nio.channels

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


      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
      channel.truncate(0);
      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
View Full Code Here


      fail();
    } catch (NonWritableChannelException expected) {
    }

    try {
      channel.truncate(0);
      fail();
    } catch (NonWritableChannelException expected) {
    }

    try {
View Full Code Here

  @Test
  public void testTruncateNegative() throws IOException {
    FileChannel channel = channel(regularFile(0), READ, WRITE);

    try {
      channel.truncate(-1);
      fail();
    } catch (IllegalArgumentException expected) {
    }
  }
View Full Code Here

                                        numObjectsBuffer.putInt(0, ii);
                                        fc.position(0);
                                        while (numObjectsBuffer.hasRemaining()) {
                                            fc.write(numObjectsBuffer);
                                        }
                                        fc.truncate(readBuffer.position() - (nextObjectLength + PBDSegment.m_objectHeaderBytes));
                                    }

                                } else {
                                    addToNumObjects(-(numObjects - objectsProcessed));
                                    //Partial object truncation
View Full Code Here

                                    readBuffer.putInt(0, ii + 1);

                                    /*
                                     * SHOULD REALLY make a copy of the original and then swap them with renaming
                                     */
                                    fc.truncate(readBuffer.position());
                                }
                                //Set last segment and break the loop over this segment
                                if (lastSegmentIndex == null) {
                                    lastSegmentIndex = segmentIndex;
                                }
View Full Code Here

                final long length = getCurrentJournalSize();
                final boolean matches = length == (_writeBuffer.position() + _writeBufferAddress) % _blockSize;
                final FileChannel channel = getFileChannel(_currentAddress);
                Debug.$assert1.t(matches);
                if (matches) {
                    channel.truncate(length);
                }
                channel.force(true);
            } catch (final IOException ioe) {
                throw new PersistitIOException(ioe);
            }
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

                final long length = getCurrentJournalSize();
                final boolean matches = length == (_writeBuffer.position() + _writeBufferAddress) % _blockSize;
                final FileChannel channel = getFileChannel(_currentAddress);
                Debug.$assert1.t(matches);
                if (matches) {
                    channel.truncate(length);
                }
                channel.force(true);
            } catch (IOException ioe) {
                throw new PersistitIOException(ioe);
            }
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

                final long length = getCurrentJournalSize();
                final boolean matches = length == (_writeBuffer.position() + _writeBufferAddress) % _blockSize;
                final FileChannel channel = getFileChannel(_currentAddress);
                Debug.$assert1.t(matches);
                if (matches) {
                    channel.truncate(length);
                }
                channel.force(true);
            } catch (final IOException ioe) {
                throw new PersistitIOException(ioe);
            }
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.