本文整理汇总了C++中FileHandle::read方法的典型用法代码示例。如果您正苦于以下问题:C++ FileHandle::read方法的具体用法?C++ FileHandle::read怎么用?C++ FileHandle::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandle
的用法示例。
在下文中一共展示了FileHandle::read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_sf_file_read_fhandle
bool test_sf_file_read_fhandle(const char *filename, const int kib_rw) {
bool result = true;
FileHandle* file = sd.open(filename, O_RDONLY);
if (file) {
timer.start();
int byte_read = 0;
while (file->read(buffer, sizeof(buffer)) == sizeof(buffer)) {
byte_read++;
}
timer.stop();
file->close();
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
notify_performance_coefficient("fs_read_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
示例2: run
//.........这里部分代码省略.........
_blocks = new FrameBlock[_blockcount];
int i = 0;
for (int y = 0; y < yblocks; ++y) {
for (int x = 0; x < xblocks; ++x) {
_blocks[i].start = ((y*blockheight) + MAX_VECTOR)*_pitch+
x*blockwidth + MAX_VECTOR;
if (xleft && x == xblocks - 1) {
_blocks[i].dx = xleft;
} else {
_blocks[i].dx = blockwidth;
}
if (yleft && y == yblocks - 1) {
_blocks[i].dy = yleft;
} else {
_blocks[i].dy = blockheight;
}
++i;
}
}
memset(&_buf1[0], 0, _bufsize);
memset(&_buf2[0], 0, _bufsize);
memset(&_work[0], 0, _bufsize);
_oldframe = &_buf1[0];
_newframe = &_buf2[0];
do {
if (inputBufferRemaining == 0) {
int bytesToRead = inputBufferSize;
if (bytesToRead > inputFileSizeRemaining)
bytesToRead = inputFileSizeRemaining;
inputPointer = &inputBuffer[0];
in.read(inputPointer, bytesToRead);
inputBufferRemaining = bytesToRead;
inputFileSizeRemaining -= bytesToRead;
}
zs.avail_in = inputBufferRemaining;
zs.next_in = inputPointer;
zs.avail_out = outputBytesRemaining;
zs.next_out = b + samples - outputBytesRemaining;
int r = inflate(&zs, Z_SYNC_FLUSH);
if (r != Z_STREAM_END && r != Z_OK)
throw Exception("inflate failed");
outputBytesRemaining = zs.avail_out;
inputPointer = zs.next_in;
inputBufferRemaining = zs.avail_in;
if (outputBytesRemaining == 0) {
if (inflateReset(&zs) != Z_OK)
throw Exception("inflateReset failed");
outputBytesRemaining = samples;
console.write(".");
decoder.decode();
bool keyFrame = false;
if (_frames % 300 == 0)
keyFrame = true;
keyFrame = true;
/* replace oldframe with new frame */
unsigned char* copyFrame = _newframe;
_newframe = _oldframe;
_oldframe = copyFrame;
compress.linesDone = 0;
示例3: create
void FilesTest::create()
{
font = new BitmapFont();
batch = new SpriteBatch();
if(Gdx.files->isExternalStorageAvailable())
{
message += "External storage available\n";
std::string externalStoragePath;
Gdx.files->getExternalStoragePath(externalStoragePath);
message += "External storage path: " + externalStoragePath + "\n";
try
{
FileHandle cube = Gdx.files->internalHandle("data/cube.obj");
std::ifstream in;
cube.read(in);
try
{
in.close();
}
catch(std::exception e)
{
}
message += "Open internal success\n";
}
catch(std::exception e)
{
message += "Couldn't open internal data/cube.obj\n";
message += e.what();
message += "\n";
}
try
{
FileHandle testFile = Gdx.files->externalHandle("test.txt");
std::ofstream testStream;
testFile.write(false, testStream);
testStream << "test";
testStream.close();
message += "Write external success\n";
}
catch(GdxRuntimeException ex)
{
message += "Couldn't open externalstorage/test.txt\n";
}
catch(std::exception e)
{
message += "Couldn't write externalstorage/test.txt\n";
}
try
{
FileHandle testFile = Gdx.files->externalHandle("test.txt");
std::ifstream in;
testFile.read(in);
in.close();
message += "Open external success\n";
}
catch(GdxRuntimeException e)
{
message += "Couldn't open internal externalstorage/test.txt\n";
}
FileHandle file = Gdx.files->externalHandle("test.txt");
if(!file.remove())
{
message += "Couldn't delete externalstorage/test.txt";
}
file = Gdx.files->externalHandle("this/is/a/test");
file.mkdirs();
file.remove();
if(!file.parent().remove())
message += "failed to remove this/is/a/ directory";
if(!file.parent().parent().parent().removeRecursive())
message += "failed to remove this directory";
}
else
{
message += "External storage not available";
}
FileHandle tmp = FileHandle::tempFile();
tmp.length();
message += "Temp file created: " + tmp.toString() + "\n";
tmp.remove();
tmp = FileHandle::tempDirectory();
if(!tmp.isDirectory())
fail();
message += "Temp directory created: " + tmp.toString() + "\n";
tmp.remove();
try
{
testInternal();
testExternal();
//.........这里部分代码省略.........
示例4: testAbsolute
void FilesTest::testAbsolute()
{
std::string path;
Gdx.files->getExternalStoragePath(path);
path += "/meow";
FileHandle handle = Gdx.files->absoluteHandle(path);
handle.remove();
if(handle.exists())
fail();
if(handle.isDirectory())
fail();
if(handle.remove())
fail();
std::vector<FileHandle> handles;
handle.list(handles);
if(handles.size() != 0)
fail();
if(handle.child("meow").exists())
fail();
if(!handle.parent().exists())
fail();
try
{
std::ifstream in;
handle.read(in);
in.close();
fail();
}
catch(GdxRuntimeException ignored)
{
}
handle.mkdirs();
if(!handle.exists())
fail();
if(!handle.isDirectory())
fail();
handle.list(handles);
if(handles.size() != 0)
fail();
handle.child("meow").mkdirs();
handle.list(handles);
if(handles.size() != 1)
fail();
FileHandle child = handles[0];
if(child.name() != "meow")
fail();
if(!child.parent().exists())
fail();
if(!handle.removeRecursive())
fail();
if(handle.exists())
fail();
std::ofstream output;
handle.write(false, output);
output << "moo";
output.close();
if(!handle.exists())
fail();
if(handle.length() != 3)
fail();
FileHandle copy = Gdx.files->absoluteHandle(path + "-copy");
copy.remove();
if(copy.exists())
fail();
handle.copyTo(copy);
if(!copy.exists())
fail();
if(copy.length() != 3)
fail();
FileHandle move = Gdx.files->absoluteHandle(path + "-move");
move.remove();
if(move.exists())
fail();
copy.moveTo(move);
if(!move.exists())
fail();
if(move.length() != 3)
fail();
move.removeRecursive();
if(move.exists())
fail();
std::ifstream input;
//.........这里部分代码省略.........
示例5: testInternal
void FilesTest::testInternal()
{
FileHandle handle = Gdx.files->internalHandle("data/badlogic.jpg");
if(!handle.exists())
fail();
if(handle.isDirectory())
fail();
try
{
handle.remove();
fail();
}
catch(GdxRuntimeException expected)
{
}
std::vector<FileHandle> files;
handle.list(files);
if(files.size() != 0)
fail();
if(!handle.parent().exists())
fail();
try
{
std::ifstream input;
handle.read(input);
input.close();
//TODO: why???
fail();
}
catch(GdxRuntimeException ignored)
{
}
FileHandle dir;
dir = Gdx.files->internalHandle("data");
if(!dir.exists())
fail();
if(!dir.isDirectory())
fail();
dir.list(files);
if(files.size() == 0)
fail();
FileHandle child = dir.child("badlogic.jpg");
if(child.name() != "badlogic.jpg")
fail();
if(child.nameWithoutExtension() != "badlogic")
fail();
if(child.extension() != "jpg")
fail();
if(!child.parent().exists())
fail();
FileHandle copy = Gdx.files->externalHandle("badlogic.jpg-copy");
copy.remove();
if(copy.exists())
fail();
handle.copyTo(copy);
if(!copy.exists())
fail();
if(copy.length() != 68465)
fail();
copy.remove();
if(copy.exists())
fail();
}