本文整理汇总了Java中java.io.RandomAccessFile.writeInt方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.writeInt方法的具体用法?Java RandomAccessFile.writeInt怎么用?Java RandomAccessFile.writeInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.writeInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: a6
import java.io.RandomAccessFile; //导入方法依赖的package包/类
public static void a6() {
try {
File file = new File(f2);
if (!file.exists()) {
File file2 = new File(I);
if (!file2.exists()) {
file2.mkdirs();
}
if (!file.createNewFile()) {
file = null;
}
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile.seek(0);
randomAccessFile.writeInt(0);
randomAccessFile.writeInt(128);
randomAccessFile.writeInt(0);
randomAccessFile.close();
}
} catch (Exception e) {
}
}
示例3: aH
import java.io.RandomAccessFile; //导入方法依赖的package包/类
private static boolean aH() {
if (eL.exists()) {
eL.delete();
}
if (!eL.getParentFile().exists()) {
eL.getParentFile().mkdirs();
}
try {
eL.createNewFile();
RandomAccessFile randomAccessFile = new RandomAccessFile(eL, "rw");
randomAccessFile.seek(0);
randomAccessFile.writeInt(0);
randomAccessFile.writeInt(0);
randomAccessFile.writeInt(1);
randomAccessFile.close();
aJ();
return eL.exists();
} catch (IOException e) {
return false;
}
}
示例4: save
import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public void save(String key, Object value) {
if (key == null) {
return;
}
// 值为空则删除
if (value == null) {
remove(key);
return;
}
try {
byte[] bytes = object2bytes(value);
if (bytes == null) {
return;
}
// 写文件
File dataFile = key2file(key);
dataFile.getParentFile().mkdirs();// 创建目录
RandomAccessFile file = new RandomAccessFile(dataFile, "rws");
file.seek(0);
file.writeUTF(key);// 写主键
file.writeInt(bytes.length);// 写值长度
file.write(bytes);// 写值字节数组
file.close();
} catch (Exception e) {
log.error(String.format("键值保存失败 %s %s", key, value), e);
}
}
示例5: Writer
import java.io.RandomAccessFile; //导入方法依赖的package包/类
Writer(File file, int logFileID, long maxFileSize,
long usableSpaceRefreshInterval)
throws IOException {
super(file, logFileID, maxFileSize, null, usableSpaceRefreshInterval,
true, 0);
RandomAccessFile writeFileHandle = getFileHandle();
writeFileHandle.writeInt(getVersion());
writeFileHandle.writeInt(logFileID);
// checkpoint marker
writeFileHandle.writeLong(0L);
// timestamp placeholder
writeFileHandle.writeLong(0L);
getFileChannel().force(true);
}
示例6: writeDataToFileLocked
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Handy helper routine to write the UI data to a file.
*/
void writeDataToFileLocked(RandomAccessFile file,
boolean addMayo, boolean addTomato, int whichFilling)
throws IOException {
file.setLength(0L);
file.writeInt(whichFilling);
file.writeBoolean(addMayo);
file.writeBoolean(addTomato);
Log.v(TAG, "NEW STATE: mayo=" + addMayo
+ " tomato=" + addTomato
+ " filling=" + whichFilling);
}
示例7: write
import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
// throws IllegalArgumentException if not supported
WaveFileFormat waveFileFormat = (WaveFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeWaveFile(stream, waveFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( waveFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
int dataLength=bytesWritten-waveFileFormat.getHeaderSize();
int riffLength=dataLength + waveFileFormat.getHeaderSize() - 8;
RandomAccessFile raf=new RandomAccessFile(out, "rw");
// skip RIFF magic
raf.skipBytes(4);
raf.writeInt(big2little( riffLength ));
// skip WAVE magic, fmt_ magic, fmt_ length, fmt_ chunk, data magic
raf.skipBytes(4+4+4+WaveFileFormat.getFmtChunkSize(waveFileFormat.getWaveType())+4);
raf.writeInt(big2little( dataLength ));
// that's all
raf.close();
}
return bytesWritten;
}
示例8: write
import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
// throws IllegalArgumentException if not supported
AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeAuFile(stream, auFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( auFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
// $$kk: 10.22.99: jan: please either implement this or throw an exception!
// $$fb: 2001-07-13: done. Fixes Bug 4479981
RandomAccessFile raf=new RandomAccessFile(out, "rw");
if (raf.length()<=0x7FFFFFFFl) {
// skip AU magic and data offset field
raf.skipBytes(8);
raf.writeInt(bytesWritten-AuFileFormat.AU_HEADERSIZE);
// that's all
}
raf.close();
}
return bytesWritten;
}
示例9: 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;
}
示例10: corruptAfterStartSegment
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Corrupt an edit log file after the start segment transaction
*/
private void corruptAfterStartSegment(File f) throws IOException {
RandomAccessFile raf = new RandomAccessFile(f, "rw");
raf.seek(0x20); // skip version and first tranaction and a bit of next transaction
for (int i = 0; i < 1000; i++) {
raf.writeInt(0xdeadbeef);
}
raf.close();
}
示例11: write
import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
Objects.requireNonNull(stream);
Objects.requireNonNull(fileType);
Objects.requireNonNull(out);
// throws IllegalArgumentException if not supported
WaveFileFormat waveFileFormat = (WaveFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeWaveFile(stream, waveFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( waveFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
int dataLength=bytesWritten-waveFileFormat.getHeaderSize();
int riffLength=dataLength + waveFileFormat.getHeaderSize() - 8;
RandomAccessFile raf=new RandomAccessFile(out, "rw");
// skip RIFF magic
raf.skipBytes(4);
raf.writeInt(big2little( riffLength ));
// skip WAVE magic, fmt_ magic, fmt_ length, fmt_ chunk, data magic
raf.skipBytes(4+4+4+WaveFileFormat.getFmtChunkSize(waveFileFormat.getWaveType())+4);
raf.writeInt(big2little( dataLength ));
// that's all
raf.close();
}
return bytesWritten;
}
示例12: write
import java.io.RandomAccessFile; //导入方法依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
Objects.requireNonNull(stream);
Objects.requireNonNull(fileType);
Objects.requireNonNull(out);
// throws IllegalArgumentException if not supported
AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeAiffFile(stream, aiffFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( aiffFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
// $$kk: 10.22.99: jan: please either implement this or throw an exception!
// $$fb: 2001-07-13: done. Fixes Bug 4479981
int channels = aiffFileFormat.getFormat().getChannels();
int sampleSize = aiffFileFormat.getFormat().getSampleSizeInBits();
int ssndBlockSize = channels * ((sampleSize + 7) / 8);
int aiffLength=bytesWritten;
int ssndChunkSize=aiffLength-aiffFileFormat.getHeaderSize()+16;
long dataSize=ssndChunkSize-16;
//TODO possibly incorrect round
int numFrames = (int) (dataSize / ssndBlockSize);
RandomAccessFile raf=new RandomAccessFile(out, "rw");
// skip FORM magic
raf.skipBytes(4);
raf.writeInt(aiffLength-8);
// skip aiff2 magic, fver chunk, comm magic, comm size, channel count,
raf.skipBytes(4+aiffFileFormat.getFverChunkSize()+4+4+2);
// write frame count
raf.writeInt(numFrames);
// skip sample size, samplerate, SSND magic
raf.skipBytes(2+10+4);
raf.writeInt(ssndChunkSize-8);
// that's all
raf.close();
}
return bytesWritten;
}
示例13: onRestore
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* On restore, we pull the various bits of data out of the restore stream,
* then reconstruct the application's data file inside the shared lock. A
* restore data set will always be the full set of records supplied by the
* application's backup operations.
*/
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
// Consume the restore data set, remembering each bit of application state
// that we see along the way
while (data.readNextHeader()) {
String key = data.getKey();
int dataSize = data.getDataSize();
// In this implementation, we trust that we won't see any record keys
// that we don't understand. Since we expect to handle them all, we
// go ahead and extract the data for each record before deciding how
// it will be handled.
byte[] dataBuf = new byte[dataSize];
data.readEntityData(dataBuf, 0, dataSize);
ByteArrayInputStream instream = new ByteArrayInputStream(dataBuf);
DataInputStream in = new DataInputStream(instream);
if (FILLING_KEY.equals(key)) {
mFilling = in.readInt();
} else if (MAYO_KEY.equals(key)) {
mAddMayo = in.readBoolean();
} else if (TOMATO_KEY.equals(key)) {
mAddTomato = in.readBoolean();
}
}
// Now we're ready to write out a full new dataset for the application. Note that
// the restore process is intended to *replace* any existing or default data, so
// we can just go ahead and overwrite it all.
synchronized (BackupRestoreActivity.sDataLock) {
RandomAccessFile file = new RandomAccessFile(mDataFile, "rw");
file.setLength(0L);
file.writeInt(mFilling);
file.writeBoolean(mAddMayo);
file.writeBoolean(mAddTomato);
}
// Finally, write the state file that describes our data as of this restore pass.
writeStateFile(newState);
}
示例14: onRestore
import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* This application does not do any "live" restores of its own data,
* so the only time a restore will happen is when the application is
* installed. This means that the activity itself is not going to
* be running while we change its data out from under it. That, in
* turn, means that there is no need to send out any sort of notification
* of the new data: we only need to read the data from the stream
* provided here, build the application's new data file, and then
* write our new backup state blob that will be consulted at the next
* backup operation.
*
* <p>We don't bother checking the versionCode of the app who originated
* the data because we have never revised the backup data format. If
* we had, the 'appVersionCode' parameter would tell us how we should
* interpret the data we're about to read.
*/
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
// We should only see one entity in the data stream, but the safest
// way to consume it is using a while() loop
while (data.readNextHeader()) {
String key = data.getKey();
int dataSize = data.getDataSize();
if (APP_DATA_KEY.equals(key)) {
// It's our saved data, a flattened chunk of data all in
// one buffer. Use some handy structured I/O classes to
// extract it.
byte[] dataBuf = new byte[dataSize];
data.readEntityData(dataBuf, 0, dataSize);
ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
DataInputStream in = new DataInputStream(baStream);
mFilling = in.readInt();
mAddMayo = in.readBoolean();
mAddTomato = in.readBoolean();
// Now we are ready to construct the app's data file based
// on the data we are restoring from.
synchronized (BackupRestoreActivity.sDataLock) {
RandomAccessFile file = new RandomAccessFile(mDataFile, "rw");
file.setLength(0L);
file.writeInt(mFilling);
file.writeBoolean(mAddMayo);
file.writeBoolean(mAddTomato);
}
} else {
// Curious! This entity is data under a key we do not
// understand how to process. Just skip it.
data.skipEntityData();
}
}
// The last thing to do is write the state blob that describes the
// app's data as restored from backup.
writeStateFile(newState);
}
示例15: write
import java.io.RandomAccessFile; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
// throws IllegalArgumentException if not supported
AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeAiffFile(stream, aiffFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( aiffFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
// $$kk: 10.22.99: jan: please either implement this or throw an exception!
// $$fb: 2001-07-13: done. Fixes Bug 4479981
int ssndBlockSize = (aiffFileFormat.getFormat().getChannels() * aiffFileFormat.getFormat().getSampleSizeInBits());
int aiffLength=bytesWritten;
int ssndChunkSize=aiffLength-aiffFileFormat.getHeaderSize()+16;
long dataSize=ssndChunkSize-16;
int numFrames=(int) (dataSize*8/ssndBlockSize);
RandomAccessFile raf=new RandomAccessFile(out, "rw");
// skip FORM magic
raf.skipBytes(4);
raf.writeInt(aiffLength-8);
// skip aiff2 magic, fver chunk, comm magic, comm size, channel count,
raf.skipBytes(4+aiffFileFormat.getFverChunkSize()+4+4+2);
// write frame count
raf.writeInt(numFrames);
// skip sample size, samplerate, SSND magic
raf.skipBytes(2+10+4);
raf.writeInt(ssndChunkSize-8);
// that's all
raf.close();
}
return bytesWritten;
}