本文整理汇总了Java中org.apache.cassandra.io.util.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于org.apache.cassandra.io.util包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureCapacity
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
/**
* Ensure {@code buf} is large enough for {@code outputLength}. If not, it is cleaned up and a new buffer is allocated;
* else; buffer has it's position/limit set appropriately.
*
* @param buf buffer to test the size of; may be null, in which case, a new buffer is allocated.
* @param outputLength the minimum target size of the buffer
* @param allowBufferResize true if resizing (reallocating) the buffer is allowed
* @param bufferType on- or off- heap byte buffer
* @return {@code buf} if it was large enough, else a newly allocated buffer.
*/
public static ByteBuffer ensureCapacity(ByteBuffer buf, int outputLength, boolean allowBufferResize, BufferType bufferType)
{
if (0 > outputLength)
throw new IllegalArgumentException("invalid size for output buffer: " + outputLength);
if (buf == null || buf.capacity() < outputLength)
{
if (!allowBufferResize)
throw new IllegalStateException(String.format("output buffer is not large enough for data: current capacity %d, required %d", buf.capacity(), outputLength));
FileUtils.clean(buf);
buf = bufferType.allocate(outputLength);
}
else
{
buf.position(0).limit(outputLength);
}
return buf;
}
示例2: delete
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
/**
* We use a ReferenceQueue to manage deleting files that have been compacted
* and for which no more SSTable references exist. But this is not guaranteed
* to run for each such file because of the semantics of the JVM gc. So,
* we write a marker to `compactedFilename` when a file is compacted;
* if such a marker exists on startup, the file should be removed.
*
* This method will also remove SSTables that are marked as temporary.
*
* @return true if the file was deleted
*/
public static boolean delete(Descriptor desc, Set<Component> components)
{
// remove the DATA component first if it exists
if (components.contains(Component.DATA))
FileUtils.deleteWithConfirm(desc.filenameFor(Component.DATA));
for (Component component : components)
{
if (component.equals(Component.DATA) || component.equals(Component.SUMMARY))
continue;
FileUtils.deleteWithConfirm(desc.filenameFor(component));
}
if (components.contains(Component.SUMMARY))
FileUtils.delete(desc.filenameFor(Component.SUMMARY));
logger.trace("Deleted {}", desc);
return true;
}
示例3: loadProperties
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
private static Properties loadProperties()
{
Properties properties = new Properties();
InputStream stream = InvertedIndex.class.getClassLoader().getResourceAsStream("InvertedIndex.properties");
try
{
properties.load(stream);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
finally
{
FileUtils.closeQuietly(stream);
}
logger.info("loaded property file, InvertedIndex.properties");
return properties;
}
示例4: dumpInterArrivalTimes
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
/**
* Dump the inter arrival times for examination if necessary.
*/
public void dumpInterArrivalTimes()
{
File file = FileUtils.createTempFile("failuredetector-", ".dat");
OutputStream os = null;
try
{
os = new BufferedOutputStream(new FileOutputStream(file, true));
os.write(toString().getBytes());
}
catch (IOException e)
{
throw new FSWriteError(e, file);
}
finally
{
FileUtils.closeQuietly(os);
}
}
示例5: recycleSegment
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
/**
* Differs from the above because it can work on any file instead of just existing
* commit log segments managed by this manager.
*
* @param file segment file that is no longer in use.
*/
void recycleSegment(final File file)
{
if (isCapExceeded()
|| CommitLogDescriptor.fromFileName(file.getName()).getMessagingVersion() != MessagingService.current_version)
{
// (don't decrease managed size, since this was never a "live" segment)
logger.debug("(Unopened) segment {} is no longer needed and will be deleted now", file);
FileUtils.deleteWithConfirm(file);
return;
}
logger.debug("Recycling {}", file);
// this wasn't previously a live segment, so add it to the managed size when we make it live
size.addAndGet(DatabaseDescriptor.getCommitLogSegmentSize());
segmentManagementTasks.add(new Callable<CommitLogSegment>()
{
public CommitLogSegment call()
{
return new CommitLogSegment(file.getPath());
}
});
}
示例6: failStartupIfInvalidSSTablesFound
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
@Test
public void failStartupIfInvalidSSTablesFound() throws Exception
{
startupChecks = startupChecks.withTest(StartupChecks.checkSSTablesFormat);
copyInvalidLegacySSTables(sstableDir);
verifyFailure(startupChecks, "Detected unreadable sstables");
// we should ignore invalid sstables in a snapshots directory
FileUtils.deleteRecursive(sstableDir.toFile());
Path snapshotDir = sstableDir.resolve("snapshots");
Files.createDirectories(snapshotDir);
copyInvalidLegacySSTables(snapshotDir); startupChecks.verify();
// and in a backups directory
FileUtils.deleteRecursive(sstableDir.toFile());
Path backupDir = sstableDir.resolve("backups");
Files.createDirectories(backupDir);
copyInvalidLegacySSTables(backupDir);
startupChecks.verify();
}
示例7: beforeClass
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws IOException
{
FileUtils.setFSErrorHandler(new DefaultFSErrorHandler());
for (String table : TABLES)
{
UUID tableID = CFMetaData.generateLegacyCfId(KS, table);
CFM.add(CFMetaData.Builder.create(KS, table)
.withId(tableID)
.addPartitionKey("thekey", UTF8Type.instance)
.addClusteringColumn("thecolumn", UTF8Type.instance)
.build());
}
tempDataDir = File.createTempFile("cassandra", "unittest");
tempDataDir.delete(); // hack to create a temp dir
tempDataDir.mkdir();
Directories.overrideDataDirectoriesForTest(tempDataDir.getPath());
// Create two fake data dir for tests, one using CF directories, one that do not.
createTestFiles();
}
示例8: writeChecksum
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
protected void writeChecksum(long checksum, String filePath)
{
File outFile = new File(filePath);
BufferedWriter out = null;
try
{
out = Files.newBufferedWriter(outFile.toPath(), Charsets.UTF_8);
out.write(String.valueOf(checksum));
out.flush();
out.close();
}
catch (IOException e)
{
throw new FSWriteError(e, outFile);
}
finally
{
FileUtils.closeQuietly(out);
}
}
示例9: buildSummaryAtLevel
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
private IndexSummary buildSummaryAtLevel(int newSamplingLevel) throws IOException
{
// we read the positions in a BRAF so we don't have to worry about an entry spanning a mmap boundary.
RandomAccessReader primaryIndex = RandomAccessReader.open(new File(descriptor.filenameFor(Component.PRIMARY_INDEX)));
try
{
long indexSize = primaryIndex.length();
try (IndexSummaryBuilder summaryBuilder = new IndexSummaryBuilder(estimatedKeys(), metadata.getMinIndexInterval(), newSamplingLevel))
{
long indexPosition;
while ((indexPosition = primaryIndex.getFilePointer()) != indexSize)
{
summaryBuilder.maybeAddEntry(partitioner.decorateKey(ByteBufferUtil.readWithShortLength(primaryIndex)), indexPosition);
RowIndexEntry.Serializer.skip(primaryIndex);
}
return summaryBuilder.build(partitioner);
}
}
finally
{
FileUtils.closeQuietly(primaryIndex);
}
}
示例10: cleanup
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
@After
public void cleanup()
{
try {
FileUtils.deleteRecursive(tmpdir);
} catch (FSWriteError e) {
/**
* Windows does not allow a mapped file to be deleted, so we probably forgot to clean the buffers somewhere.
* We force a GC here to force buffer deallocation, and then try deleting the directory again.
* For more information, see: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4715154
* If this is not the problem, the exception will be rethrown anyway.
*/
System.gc();
FileUtils.deleteRecursive(tmpdir);
}
}
示例11: testSerialization
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
@Test
public void testSerialization() throws IOException
{
Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1);
ByteArrayOutputStream aos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(aos);
IndexSummary.serializer.serialize(random.right, dos);
// write junk
dos.writeUTF("JUNK");
dos.writeUTF("JUNK");
FileUtils.closeQuietly(dos);
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(aos.toByteArray()));
IndexSummary is = IndexSummary.serializer.deserialize(dis, DatabaseDescriptor.getPartitioner());
for (int i = 0; i < 100; i++)
assertEquals(i, is.binarySearch(random.left.get(i)));
// read the junk
assertEquals(dis.readUTF(), "JUNK");
assertEquals(dis.readUTF(), "JUNK");
FileUtils.closeQuietly(dis);
}
示例12: appendTOC
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
/**
* Appends new component names to the TOC component.
*/
protected static void appendTOC(Descriptor descriptor, Collection<Component> components)
{
File tocFile = new File(descriptor.filenameFor(Component.TOC));
PrintWriter w = null;
try
{
w = new PrintWriter(new FileWriter(tocFile, true));
for (Component component : components)
w.println(component.name);
}
catch (IOException e)
{
throw new FSWriteError(e, tocFile);
}
finally
{
FileUtils.closeQuietly(w);
}
}
示例13: skipIndex
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
/**
* Skip the index
* @param in the data input from which the index should be skipped
* @throws IOException if an I/O error occurs.
*/
public static void skipIndex(DataInput in) throws IOException
{
/* read only the column index list */
int columnIndexSize = in.readInt();
/* skip the column index data */
if (in instanceof FileDataInput)
{
FileUtils.skipBytesFully(in, columnIndexSize);
}
else
{
// skip bytes
byte[] skip = new byte[columnIndexSize];
in.readFully(skip);
}
}
示例14: testHugeBFSerialization
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
@Test
@Ignore
public void testHugeBFSerialization() throws IOException
{
ByteBuffer test = ByteBuffer.wrap(new byte[] {0, 1});
File file = FileUtils.createTempFile("bloomFilterTest-", ".dat");
BloomFilter filter = (BloomFilter) FilterFactory.getFilter(((long)Integer.MAX_VALUE / 8) + 1, 0.01d, true);
filter.add(test);
DataOutputStreamAndChannel out = new DataOutputStreamAndChannel(new FileOutputStream(file));
FilterFactory.serialize(filter, out);
filter.bitset.serialize(out);
out.close();
filter.close();
DataInputStream in = new DataInputStream(new FileInputStream(file));
BloomFilter filter2 = (BloomFilter) FilterFactory.deserialize(in, true);
Assert.assertTrue(filter2.isPresent(test));
FileUtils.closeQuietly(in);
}
示例15: testSerialization
import org.apache.cassandra.io.util.FileUtils; //导入依赖的package包/类
@Test
public void testSerialization() throws IOException
{
Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1);
DataOutputBuffer dos = new DataOutputBuffer();
IndexSummary.serializer.serialize(random.right, dos, false);
// write junk
dos.writeUTF("JUNK");
dos.writeUTF("JUNK");
FileUtils.closeQuietly(dos);
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray()));
IndexSummary is = IndexSummary.serializer.deserialize(dis, DatabaseDescriptor.getPartitioner(), false, 1, 1);
for (int i = 0; i < 100; i++)
assertEquals(i, is.binarySearch(random.left.get(i)));
// read the junk
assertEquals(dis.readUTF(), "JUNK");
assertEquals(dis.readUTF(), "JUNK");
is.close();
FileUtils.closeQuietly(dis);
}