List of usage examples for java.io RandomAccessFile writeShort
public final void writeShort(int v) throws IOException
From source file:Main.java
public static void main(String[] args) { try {/*from w w w.j av a2 s.c o m*/ short s = 15; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeShort(s); raf.seek(0); System.out.println(raf.readShort()); raf.seek(0); raf.writeShort(20); raf.seek(0); System.out.println(raf.readShort()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {// www. j a v a 2s. c o m short s = 15000; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeShort(s); // set the file pointer at 0 position raf.seek(0); // print the short System.out.println(raf.readShort()); // set the file pointer at 0 position raf.seek(0); // write something in the file raf.writeShort(134); // set the file pointer at 0 position raf.seek(0); // print the short System.out.println(raf.readShort()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.apache.activemq.store.kahadb.KahaDBStoreRecoveryBrokerTest.java
@Override @SuppressWarnings("resource") protected BrokerService createRestartedBroker() throws Exception { // corrupting index File index = new File(kahaDbDirectoryName + "/db.data"); RandomAccessFile raf = new RandomAccessFile(index, "rw"); switch (failTest) { case FailToLoad: index.delete();//from w w w . j a v a 2s .c o m raf = new RandomAccessFile(index, "rw"); raf.seek(index.length()); raf.writeBytes("corrupt"); break; case LoadInvalid: // page size 0 raf.seek(0); raf.writeBytes("corrupt and cannot load metadata"); break; case LoadCorrupt: // loadable but invalid metadata // location of order index low priority index for first destination... raf.seek(8 * 1024 + 57); raf.writeLong(Integer.MAX_VALUE - 10); break; case LoadOrderIndex0: // loadable but invalid metadata // location of order index default priority index size // so looks like there are no ids in the order index // picked up by setCheckForCorruptJournalFiles raf.seek(12 * 1024 + 21); raf.writeShort(0); raf.writeChar(0); raf.writeLong(-1); break; default: } raf.close(); // starting broker BrokerService broker = new BrokerService(); KahaDBStore kaha = new KahaDBStore(); kaha.setCheckForCorruptJournalFiles(failTest == CorruptionType.LoadOrderIndex0); // uncomment if you want to test archiving //kaha.setArchiveCorruptedIndex(true); kaha.setDirectory(new File(kahaDbDirectoryName)); broker.setPersistenceAdapter(kaha); return broker; }