当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.writeShort方法代码示例

本文整理汇总了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;
}
 
开发者ID:alibaba,项目名称:virtualview_tools,代码行数:26,代码来源:StringStore.java

示例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;
}
 
开发者ID:alibaba,项目名称:virtualview_tools,代码行数:26,代码来源:ExprCodeStore.java

示例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;
}
 
开发者ID:vassela,项目名称:AC2RD,代码行数:40,代码来源:RecordFileWriter.java


注:本文中的java.io.RandomAccessFile.writeShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。