本文整理汇总了Java中org.apache.cassandra.io.util.SequentialWriter.open方法的典型用法代码示例。如果您正苦于以下问题:Java SequentialWriter.open方法的具体用法?Java SequentialWriter.open怎么用?Java SequentialWriter.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.io.util.SequentialWriter
的用法示例。
在下文中一共展示了SequentialWriter.open方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeMetadata
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
private static void writeMetadata(Descriptor desc, Map<MetadataType, MetadataComponent> components)
{
SequentialWriter out = SequentialWriter.open(new File(desc.filenameFor(Component.STATS)));
try
{
desc.getMetadataSerializer().serialize(components, out.stream);
}
catch (IOException e)
{
throw new FSWriteError(e, out.getPath());
}
finally
{
out.close();
}
}
示例2: SSTableWriter
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
public SSTableWriter(String filename,
long keyCount,
long repairedAt,
CFMetaData metadata,
IPartitioner<?> partitioner,
MetadataCollector sstableMetadataCollector)
{
super(Descriptor.fromFilename(filename),
components(metadata),
metadata,
partitioner);
this.repairedAt = repairedAt;
iwriter = new IndexWriter(keyCount);
if (compression)
{
dataFile = SequentialWriter.open(getFilename(),
descriptor.filenameFor(Component.COMPRESSION_INFO),
metadata.compressionParameters(),
sstableMetadataCollector);
dbuilder = SegmentedFile.getCompressedBuilder((CompressedSequentialWriter) dataFile);
}
else
{
dataFile = SequentialWriter.open(new File(getFilename()), new File(descriptor.filenameFor(Component.CRC)));
dbuilder = SegmentedFile.getBuilder(DatabaseDescriptor.getDiskAccessMode());
}
this.sstableMetadataCollector = sstableMetadataCollector;
}
示例3: IndexWriter
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
IndexWriter(long keyCount)
{
indexFile = SequentialWriter.open(new File(descriptor.filenameFor(Component.PRIMARY_INDEX)));
builder = SegmentedFile.getBuilder(DatabaseDescriptor.getIndexAccessMode());
summary = new IndexSummaryBuilder(keyCount, metadata.getMinIndexInterval(), Downsampling.BASE_SAMPLING_LEVEL);
bf = FilterFactory.getFilter(keyCount, metadata.getBloomFilterFpChance(), true);
}
示例4: testLength
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
@Test
public void testLength() throws IOException {
File tmpFile = File.createTempFile("lengthtest", "bin");
SequentialWriter w = SequentialWriter.open(tmpFile);
assertEquals(0, w.length());
// write a chunk smaller then our buffer, so will not be flushed
// to disk
byte[] lessThenBuffer = generateByteArray(RandomAccessReader.DEFAULT_BUFFER_SIZE / 2);
w.write(lessThenBuffer);
assertEquals(lessThenBuffer.length, w.length());
// sync the data and check length
w.sync();
assertEquals(lessThenBuffer.length, w.length());
// write more then the buffer can hold and check length
byte[] biggerThenBuffer = generateByteArray(RandomAccessReader.DEFAULT_BUFFER_SIZE * 2);
w.write(biggerThenBuffer);
assertEquals(biggerThenBuffer.length + lessThenBuffer.length, w.length());
w.close();
// will use cachedlength
RandomAccessReader r = RandomAccessReader.open(new Path(tmpFile.getPath()), fs);
assertEquals(lessThenBuffer.length + biggerThenBuffer.length, r.length());
r.close();
}
示例5: tempCacheFile
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
private SequentialWriter tempCacheFile(Pair<String, String> pathInfo)
{
File path = getCachePath(pathInfo.left, pathInfo.right, CURRENT_VERSION);
File tmpFile = FileUtils.createTempFile(path.getName(), null, path.getParentFile());
return SequentialWriter.open(tmpFile, true);
}
示例6: testReadMethods
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
@Test
public void testReadMethods() throws IOException
{
// Make sure this array is bigger than the reader buffer size
// so we test updating the crc across buffer boundaries
byte[] b = new byte[RandomAccessReader.DEFAULT_BUFFER_SIZE * 2];
for (int i = 0; i < b.length; i++)
b[i] = (byte)i;
ByteBuffer buffer;
// fill a bytebuffer with some input
try (DataOutputBuffer out = new DataOutputBuffer())
{
out.write(127);
out.write(b);
out.writeBoolean(false);
out.writeByte(10);
out.writeChar('t');
out.writeDouble(3.3);
out.writeFloat(2.2f);
out.writeInt(42);
out.writeLong(Long.MAX_VALUE);
out.writeShort(Short.MIN_VALUE);
out.writeUTF("utf");
out.writeVInt(67L);
out.writeUnsignedVInt(88L);
out.writeBytes("abcdefghi");
buffer = out.buffer();
}
// calculate expected CRC
CRC32 crc = new CRC32();
FBUtilities.updateChecksum(crc, buffer);
// save the buffer to file to create a RAR
File file = File.createTempFile("testReadMethods", "1");
file.deleteOnExit();
try (SequentialWriter writer = SequentialWriter.open(file))
{
writer.write(buffer);
writer.writeInt((int) crc.getValue());
writer.finish();
}
assertTrue(file.exists());
assertEquals(buffer.remaining() + 4, file.length());
try (ChecksummedDataInput reader = ChecksummedDataInput.open(file))
{
reader.limit(buffer.remaining() + 4);
// assert that we read all the right values back
assertEquals(127, reader.read());
byte[] bytes = new byte[b.length];
reader.readFully(bytes);
assertTrue(Arrays.equals(bytes, b));
assertEquals(false, reader.readBoolean());
assertEquals(10, reader.readByte());
assertEquals('t', reader.readChar());
assertEquals(3.3, reader.readDouble());
assertEquals(2.2f, reader.readFloat());
assertEquals(42, reader.readInt());
assertEquals(Long.MAX_VALUE, reader.readLong());
assertEquals(Short.MIN_VALUE, reader.readShort());
assertEquals("utf", reader.readUTF());
assertEquals(67L, reader.readVInt());
assertEquals(88L, reader.readUnsignedVInt());
assertEquals("abcdefghi", new String(ByteBufferUtil.read(reader, 9).array(), StandardCharsets.UTF_8));
// assert that the crc matches, and that we've read exactly as many bytes as expected
assertTrue(reader.checkCrc());
assertEquals(0, reader.bytesRemaining());
reader.checkLimit(0);
}
}
示例7: testResetCrc
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
@Test
public void testResetCrc() throws IOException
{
CRC32 crc = new CRC32();
ByteBuffer buffer;
// fill a bytebuffer with some input
try (DataOutputBuffer out = new DataOutputBuffer())
{
out.write(127);
out.writeBoolean(false);
out.writeByte(10);
out.writeChar('t');
buffer = out.buffer();
FBUtilities.updateChecksum(crc, buffer);
out.writeInt((int) crc.getValue());
int bufferPos = out.getLength();
out.writeDouble(3.3);
out.writeFloat(2.2f);
out.writeInt(42);
buffer = out.buffer();
buffer.position(bufferPos);
crc.reset();
FBUtilities.updateChecksum(crc, buffer);
out.writeInt((int) crc.getValue());
buffer = out.buffer();
}
// save the buffer to file to create a RAR
File file = File.createTempFile("testResetCrc", "1");
file.deleteOnExit();
try (SequentialWriter writer = SequentialWriter.open(file))
{
writer.write(buffer);
writer.finish();
}
assertTrue(file.exists());
assertEquals(buffer.remaining(), file.length());
try (ChecksummedDataInput reader = ChecksummedDataInput.open(file))
{
reader.limit(buffer.remaining());
// assert that we read all the right values back
assertEquals(127, reader.read());
assertEquals(false, reader.readBoolean());
assertEquals(10, reader.readByte());
assertEquals('t', reader.readChar());
assertTrue(reader.checkCrc());
reader.resetCrc();
assertEquals(3.3, reader.readDouble());
assertEquals(2.2f, reader.readFloat());
assertEquals(42, reader.readInt());
assertTrue(reader.checkCrc());
assertEquals(0, reader.bytesRemaining());
}
}
示例8: testFailedCrc
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
@Test
public void testFailedCrc() throws IOException
{
CRC32 crc = new CRC32();
ByteBuffer buffer;
// fill a bytebuffer with some input
try (DataOutputBuffer out = new DataOutputBuffer())
{
out.write(127);
out.writeBoolean(false);
out.writeByte(10);
out.writeChar('t');
buffer = out.buffer();
FBUtilities.updateChecksum(crc, buffer);
// update twice so it won't match
FBUtilities.updateChecksum(crc, buffer);
out.writeInt((int) crc.getValue());
buffer = out.buffer();
}
// save the buffer to file to create a RAR
File file = File.createTempFile("testFailedCrc", "1");
file.deleteOnExit();
try (SequentialWriter writer = SequentialWriter.open(file))
{
writer.write(buffer);
writer.finish();
}
assertTrue(file.exists());
assertEquals(buffer.remaining(), file.length());
try (ChecksummedDataInput reader = ChecksummedDataInput.open(file))
{
reader.limit(buffer.remaining());
// assert that we read all the right values back
assertEquals(127, reader.read());
assertEquals(false, reader.readBoolean());
assertEquals(10, reader.readByte());
assertEquals('t', reader.readChar());
assertFalse(reader.checkCrc());
assertEquals(0, reader.bytesRemaining());
}
}
示例9: tempCacheFile
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
private SequentialWriter tempCacheFile(UUID cfId)
{
File path = getCachePath(cfId, CURRENT_VERSION);
File tmpFile = FileUtils.createTempFile(path.getName(), null, path.getParentFile());
return SequentialWriter.open(tmpFile);
}
示例10: tempCacheFile
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
private SequentialWriter tempCacheFile(CacheKey.PathInfo pathInfo)
{
File path = getCachePath(pathInfo.keyspace, pathInfo.columnFamily, pathInfo.cfId, CURRENT_VERSION);
File tmpFile = FileUtils.createTempFile(path.getName(), null, path.getParentFile());
return SequentialWriter.open(tmpFile, true);
}
示例11: createTempFile
import org.apache.cassandra.io.util.SequentialWriter; //导入方法依赖的package包/类
private SequentialWriter createTempFile(String name) throws IOException {
File tempFile = File.createTempFile(name, null);
tempFile.deleteOnExit();
return SequentialWriter.open(tempFile);
}