1 11 package org.eclipse.core.internal.indexing; 12 13 import java.io.FileOutputStream ; 14 import java.io.IOException ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 class LogWriter { 19 20 protected FileOutputStream out; 21 protected PageStore pageStore; 22 23 26 public static void putModifiedPages(PageStore pageStore, Map modifiedPages) throws PageStoreException { 27 LogWriter writer = new LogWriter(); 28 try { 29 writer.open(pageStore); 30 writer.putModifiedPages(modifiedPages); 31 } finally { 32 writer.close(); 33 } 34 } 35 36 39 protected void open(PageStore store) throws PageStoreException { 40 this.pageStore = store; 41 try { 42 out = new FileOutputStream (Log.name(store.getName())); 43 } catch (IOException e) { 44 throw new PageStoreException(PageStoreException.LogOpenFailure, e); 45 } 46 } 47 48 51 protected void close() { 52 try { 53 if (out != null) 54 out.close(); 55 } catch (IOException e) { 56 } 58 out = null; 59 } 60 61 64 protected void putModifiedPages(Map modifiedPages) throws PageStoreException { 65 Buffer b4 = new Buffer(4); 66 byte[] pageBuffer = new byte[Page.SIZE]; 67 int numberOfPages = modifiedPages.size(); 68 b4.put(0, 4, numberOfPages); 69 try { 70 write(b4.getByteArray()); 71 Iterator pageStream = modifiedPages.values().iterator(); 72 while (pageStream.hasNext()) { 73 Page page = (Page) pageStream.next(); 74 int pageNumber = page.getPageNumber(); 75 b4.put(0, 4, pageNumber); 76 write(b4.getByteArray()); 77 page.toBuffer(pageBuffer); 78 write(pageBuffer); 79 } 80 } catch (IOException e) { 81 throw new PageStoreException(PageStoreException.LogWriteFailure, e); 82 } 83 } 84 85 public void write(byte[] buffer) throws IOException { 86 out.write(buffer); 87 } 88 89 } 90 | Popular Tags |