本文整理匯總了Java中java.io.RandomAccessFile.writeShort方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomAccessFile.writeShort方法的具體用法?Java RandomAccessFile.writeShort怎麽用?Java RandomAccessFile.writeShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.writeShort方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: storeToFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public int storeToFile(RandomAccessFile file) {
int totalSize = 0;
if (null != file) {
try {
int size = mSingleOutputString2Index.size();
file.writeInt(size);
Iterator<String> iterator = mSingleOutputString2Index.keySet().iterator();
while (iterator.hasNext()) {
String string = iterator.next();
int index = mSingleOutputString2Index.get(string);
byte[] bs = string.getBytes();
file.writeInt(index);
file.writeShort(bs.length);
file.write(bs);
totalSize += 4 + bs.length + 2;
}
} catch (IOException e) {
Log.e(TAG, "storeToFile error:" + e);
e.printStackTrace();
}
}
return totalSize;
}
示例2: storeToFile
import java.io.RandomAccessFile; //導入方法依賴的package包/類
public int storeToFile(RandomAccessFile file) {
int totalSize = 0;
if (null != file) {
try {
file.writeInt(mCodes.size());
Iterator<ExprCode> iterator = mCodes.keySet().iterator();
while (iterator.hasNext()) {
ExprCode code = iterator.next();
Integer integer = mCodes.get(code);
file.writeInt(integer.intValue());
file.writeShort(code.size());
for (byte b : code.mCodeBase) {
file.writeByte(b);
}
totalSize += 4 + code.size() + 2;
}
} catch (IOException e) {
Log.e(TAG, "storeToFile error:" + e);
e.printStackTrace();
}
}
return totalSize;
}
示例3: prepareAudioRecord
import java.io.RandomAccessFile; //導入方法依賴的package包/類
private boolean prepareAudioRecord(Context context, File recordFile, int audioRecordChannelConfig, int chanelNumber, int audioRecordAudioFormat, int nbBitsPerSample)
{
try
{
if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED)
{
audioRecordRandomAccessFile = new RandomAccessFile(recordFile.getAbsolutePath(), "rw");
audioRecordRandomAccessFile.setLength(0);
audioRecordRandomAccessFile.writeBytes("RIFF"); // 00 - Marks the file as a riff file
audioRecordRandomAccessFile.writeInt(0); // 04 - Size of the overall file
audioRecordRandomAccessFile.writeBytes("WAVE"); // 08 - File Type Header
audioRecordRandomAccessFile.writeBytes("fmt "); // 12 - Format chunk marker
audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(16)); // 16 - Length of format data as listed above
audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short) 1)); // 20 - Type of format
audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short) chanelNumber)); // 22 - Number of Channels
audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(audioRecordSampleRate)); // 24 - Sample Rate
audioRecordRandomAccessFile.writeInt(Integer.reverseBytes(audioRecordSampleRate * chanelNumber * (short)nbBitsPerSample / 8)); // 28 - ByteRate
audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short)(chanelNumber * nbBitsPerSample / 8))); // 32 - Alignment
audioRecordRandomAccessFile.writeShort(Short.reverseBytes((short) nbBitsPerSample)); // 34 - Bits per sample
audioRecordRandomAccessFile.writeBytes("data"); // 36 - "data" chunk header
audioRecordRandomAccessFile.writeInt(0); // 40 - Size of the data section
audioRecordBuffer = new byte[audioRecordPeriodInFrames * (short)nbBitsPerSample / 8 * chanelNumber];
}
else
{
Log.w("RecordFileWriter", "prepareAudioRecord : " + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare));
databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare), new Date().getTime(), 2, false);
return false;
}
}
catch (Exception e)
{
Log.w("RecordFileWriter", "prepareAudioRecord : " + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare) + " : " + e);
databaseManager.insertLog(context, "" + context.getString(R.string.log_record_file_writer_error_audiorecord_prepare), new Date().getTime(), 2, false);
return false;
}
return true;
}