本文整理汇总了C++中FileInputStream::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ FileInputStream::getPosition方法的具体用法?C++ FileInputStream::getPosition怎么用?C++ FileInputStream::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInputStream
的用法示例。
在下文中一共展示了FileInputStream::getPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getIconFromIcnsFile
static Image getIconFromIcnsFile (const File& icnsFile, const int size)
{
FileInputStream stream (icnsFile);
if (! stream.openedOk())
return {};
const int numHeaderSectionBytes = 4;
char headerSection [numHeaderSectionBytes];
if (stream.read (headerSection, numHeaderSectionBytes) != numHeaderSectionBytes
|| headerSection[0] != 'i'
|| headerSection[1] != 'c'
|| headerSection[2] != 'n'
|| headerSection[3] != 's')
return {};
if (stream.read (headerSection, numHeaderSectionBytes) != numHeaderSectionBytes)
return {};
const auto dataSize = juce::ByteOrder::bigEndianInt (headerSection);
if (dataSize <= 0)
return {};
OwnedArray<juce::ImageFileFormat> internalFormats;
internalFormats.add (new PNGImageFormat());
internalFormats.add (new JPEGImageFormat());
Array<Image> images;
auto maxWidth = 0;
auto maxWidthIndex = -1;
while (stream.getPosition() < dataSize)
{
const auto sectionStart = stream.getPosition();
if (! stream.setPosition (sectionStart + 4))
break;
if (stream.read (headerSection, numHeaderSectionBytes) != numHeaderSectionBytes)
break;
const auto sectionSize = ByteOrder::bigEndianInt (headerSection);
if (sectionSize <= 0)
break;
const auto sectionDataStart = stream.getPosition();
for (auto* fmt : internalFormats)
{
if (fmt->canUnderstand (stream))
{
stream.setPosition (sectionDataStart);
images.add (fmt->decodeImage (stream));
const auto lastImageIndex = images.size() - 1;
const auto lastWidth = images.getReference (lastImageIndex).getWidth();
if (lastWidth > maxWidth)
{
maxWidthIndex = lastImageIndex;
maxWidth = lastWidth;
}
}
stream.setPosition (sectionDataStart);
}
stream.setPosition (sectionStart + sectionSize);
}
return maxWidthIndex == -1 ? juce::Image()
: images.getReference (maxWidthIndex).rescaled (size, size, Graphics::ResamplingQuality::highResamplingQuality);
}
示例2: run
//.........这里部分代码省略.........
if (tmpStream == NULL)
{
dbgOut( L"** AudioFileConverter ** Unable to create output stream for file:\t" + audioFileName );
delete tmpAudioFile;
audioFormatWriters.clear(true);
someAudioFormats.clear(true);
audioFiles.clear(true);
outStreams.clear();
delete fileInputStream;
removeFromQueue();
continue;
}
outStreams.add( tmpStream );
/* Create Audio Format Writer */
tmpWriter = someAudioFormats[i]->createWriterFor( outStreams[i], // streamToWriteTo,
samplingRate, // sampleRateToUse,
1, // numberOfChannels,
someAudioFormats[i]->getPossibleBitDepths().getLast(), // bitsPerSample - Get the maximum possible bit depth for this format
NULL, // metadataValues,
0 );
if (tmpWriter == NULL)
{
dbgOut( L"** AudioFileConverter ** Unable to create audio format writer for:\t" + audioFileName );
delete tmpAudioFile;
audioFormatWriters.clear(true);
someAudioFormats.clear(true);
audioFiles.clear(true);
outStreams.clear();
delete fileInputStream;
removeFromQueue();
continue;
}
audioFormatWriters.add( tmpWriter );
}
// Write data to wav file
int dataBlockSize = processorOutputs * bufferSize * bitDepth/8 ;
MemoryBlock* buffer = new MemoryBlock( dataBlockSize, true);
int64 bytesSaved = inputDataFile.getSize();
while ( !fileInputStream->isExhausted() && (fileInputStream->getPosition() < bytesSaved) )
{
float* x = (float *) buffer->getData() ;
int bytesRead = fileInputStream->read( (void *)x, dataBlockSize );
int numSamples = (int)( bytesRead / bytesPerSample );
for (int ch=0; ch < processorOutputs; ch++)
{
// const int numBytes = (int) (bytesRead/processorOutputs);
tempBuffer.copyFrom( 0, // const int destChannel,
0, // const int destStartSample,
x+ch*numSamples, // const float * source,
numSamples // int numSamples
);
audioFormatWriters[ch]->write( (const int**)(tempBuffer.getArrayOfChannels()), //AudioFormatWriter * writer,
numSamples //const int numSamples
);
}
}
// clean up
delete buffer;
// this should delete 'owned' objects
audioFormatWriters.clear(true);
someAudioFormats.clear(true);
audioFiles.clear(true);
// clear the outStreams without deleting objects (already deleted)
outStreams.clear();
// Delete and close the stream
delete fileInputStream;
// Delete the data.dat file
dbgOut( L"** AudioFileConverter ** \tDeleting temporary file:\t" + inputFileName );
inputDataFile.deleteFile();
// Delete the task
removeFromQueue();
dbgOut( "** AudioFileConverter ** Files saved." );
}
dbgOut( "** AudioFileConverter ** Thread terminates." );
}