From kato-commits-return-93-apmail-incubator-kato-commits-archive=incubator.apache.org@incubator.apache.org Wed May 13 10:21:21 2009 Return-Path: Delivered-To: apmail-incubator-kato-commits-archive@minotaur.apache.org Received: (qmail 3124 invoked from network); 13 May 2009 10:21:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 May 2009 10:21:21 -0000 Received: (qmail 52514 invoked by uid 500); 13 May 2009 10:21:21 -0000 Delivered-To: apmail-incubator-kato-commits-archive@incubator.apache.org Received: (qmail 52498 invoked by uid 500); 13 May 2009 10:21:21 -0000 Mailing-List: contact kato-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: kato-dev@incubator.apache.org Delivered-To: mailing list kato-commits@incubator.apache.org Received: (qmail 52488 invoked by uid 99); 13 May 2009 10:21:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2009 10:21:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2009 10:21:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6888B2388898; Wed, 13 May 2009 10:20:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r774279 [2/2] - in /incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor: ./ .settings/ META-INF/ bin/ icons/ src/ src/org/ src/org/apache/ src/org/apache/kato/ src/org/apache/kato/tools/ src/org/apache/kato/tools/plugins/ src/org/a... Date: Wed, 13 May 2009 10:20:55 -0000 To: kato-commits@incubator.apache.org From: spoole@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090513102056.6888B2388898@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java?rev=774279&view=auto ============================================================================== --- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java (added) +++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java Wed May 13 10:20:54 2009 @@ -0,0 +1,136 @@ +/******************************************************************************* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package org.apache.kato.tools.plugins.hexeditor.views; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + +import javax.imageio.stream.FileImageInputStream; + +import org.apache.kato.tools.plugins.hexeditor.eyecatchers.Eyecatcher; +import org.apache.kato.tools.plugins.hexeditor.eyecatchers.EyecatcherScanner; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +//this is the model for the view i.e. the raw dump file +public class RawByteModel implements IStructuredContentProvider { + private FileImageInputStream file = null; + private long ptrFile = 0; //current seek pointer + private final int pageSize = 40 * 16; //number of items to display on a page + private byte[] buffer = new byte[pageSize]; //byte buffer + private int bufferSize = 0; + private EyecatcherScanner scanner = new EyecatcherScanner(); + + public RawByteModel(String path) { + try { + file = new FileImageInputStream(new RandomAccessFile(path, "r")); + readIntoBuffer(0); + } catch (FileNotFoundException e) { + throw new IllegalArgumentException("The file " + path + " does not exist or could not be found"); + } + } + + public long getOffset() { + return ptrFile; //the offset into the file + } + + //accepts either an ASCII or hex identified string + public long findData(String searchFor) { + String hex = null; + if (searchFor.startsWith("0x")) { + hex = searchFor.substring(2); //strip the 0x prefix + } else { + StringBuffer buffer = new StringBuffer(searchFor.length() * 2); //correctly intialise the buffer size + for(int i = 0; i < searchFor.length(); i++) { + buffer.append(Integer.toHexString(0xFF & searchFor.charAt(i))); + } + hex = buffer.toString(); + } + scanner.reset(); //reset the scanner + long mark = ptrFile; //note where we are in case we don't find the data we're looking for + readIntoBuffer(0); //start searching from the beginning of the data + int bufferDiscardCount = 0; //count how many times we discard the current buffer contents searching for a match + while(!isEOF()) { + if (scanner.scan(buffer, hex)) { //found the search terms + long index = (bufferDiscardCount * bufferSize); // + scanner.getEyecatcher().getLocation(); //position in file + readIntoBuffer(index); //ensure that the buffer contains a complete display page to avoid overwriting the eyecatcher + return index; + } + bufferDiscardCount++; + readIntoBuffer(bufferDiscardCount * bufferSize); //carry on reading from the current point + } + readIntoBuffer(mark); //restore where we were + return -1; //no match has been found + } + + public byte getData(long index) { + if((index < ptrFile) || ((ptrFile + bufferSize) <= index)) { //currently have required index in buffer + readIntoBuffer(index); + scanner.reset(); //if we are reading a new buffer, then invalidate the scanner + } + return buffer[(int)(index - ptrFile)]; + } + + public boolean isInRange(long index) { + return (!isEOF()) && (index < file.length()); + } + + public boolean isEOF() { + return (bufferSize == -1); + } + + private void readIntoBuffer(long index) { + if (isEOF() || (index >= file.length())) { + throw new IllegalStateException("Cannot read beyond the end of a file"); + } + try { + ptrFile = index; + file.seek(index); + bufferSize = file.read(buffer); + } catch (IOException e) { + throw new RuntimeException("Could not read data", e); + } + + } + + public Object[] getElements(Object arg0) { + return null; + } + + public void dispose() { + try { + file.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + // TODO Auto-generated method stub + + } + + public boolean hasEyeCatcher(Eyecatcher searchfor) { + return false; + } + + public boolean hasEyeCatcher() { + return scanner.hasEyecatcher(); + } + + public Eyecatcher getEyecatcher() { + return scanner.getEyecatcher(); + } +} Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java ------------------------------------------------------------------------------ svn:mime-type = text/plain