<commit_before>/**
 * 
 */
package org.mwc.debrief.core.loaders;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.mwc.cmap.plotViewer.editors.PlotEditor;
import org.mwc.debrief.core.CorePlugin;
import org.mwc.debrief.core.interfaces.IPlotLoader;
import org.eclipse.core.resources.IFile; 
import org.eclipse.core.runtime.CoreException;


import Debrief.ReaderWriter.Replay.ImportReplay;
import MWC.GUI.Layers;

/**
 * @author ian.mayo
 *
 */
public class ReplayLoader extends IPlotLoader.BaseLoader
{

	/* (non-Javadoc)
	 * @see org.mwc.debrief.core.interfaces.IPlotLoader#loadFile(org.mwc.cmap.plotViewer.editors.PlotEditor, org.eclipse.ui.IEditorInput)
	 */
	public void loadFile(PlotEditor thePlot, IEditorInput input)
	{
		String source = super.getFileName(input);
		
		Object theInput = input;
		
		Class inputClass = theInput.getClass();

	//	if(input instanceof org.eclipse.ui.part.FileEditorInput)
//		{
//			org.eclipse.ui.part.FileEditorInput ife = (org.eclipse.ui.part.FileEditorInput) input;
//			IFile _theFile = ife.getFile();
//			String theName = _theFile.getName();
			
			String theName = "d:/dev/eclipse2/runtime-workspace/test_project/boat_file.rep";
		
			try
			{
				// stick it in a stream
//				InputStream is = _theFile.getContents();
				InputStream is = new FileInputStream(theName);
				Layers theLayers = (Layers) thePlot.getAdapter(Layers.class);
				ImportReplay importer = new Debrief.ReaderWriter.Replay.ImportReplay();

				// and do the import... 
				importer.importThis(theName, is, theLayers);
			}
			catch (FileNotFoundException e)
			{
				CorePlugin.logError(org.eclipse.core.runtime.Status.ERROR,
					"Unable to open REP file for input:" + theName, e	);
			}
		
			
	//	}

		
		// ok, load the data...
		System.out.println(getName() + " LOADER: loading data");
		
	}
}
<commit_msg>Get the importer working<commit_after>/**
 * 
 */
package org.mwc.debrief.core.loaders;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.mwc.cmap.plotViewer.editors.PlotEditor;
import org.mwc.debrief.core.CorePlugin;
import org.mwc.debrief.core.interfaces.IPlotLoader;
import org.eclipse.core.resources.IFile; 
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Status;


import Debrief.ReaderWriter.Replay.ImportReplay;
import MWC.GUI.Layers;

/**
 * @author ian.mayo
 *
 */
public class ReplayLoader extends IPlotLoader.BaseLoader
{

	/* (non-Javadoc)
	 * @see org.mwc.debrief.core.interfaces.IPlotLoader#loadFile(org.mwc.cmap.plotViewer.editors.PlotEditor, org.eclipse.ui.IEditorInput)
	 */
	public void loadFile(PlotEditor thePlot, IEditorInput input)
	{
		String source = super.getFileName(input);
		
		Object theInput = input;
		
		Class inputClass = theInput.getClass();


		if(input instanceof org.eclipse.ui.part.FileEditorInput)
		{
			org.eclipse.ui.part.FileEditorInput ife = (org.eclipse.ui.part.FileEditorInput) input;
			final IFile _theFile = ife.getFile();
			String theName = _theFile.getName();
			
			String thePath = _theFile.getFullPath().toOSString();
			IPath iPath = _theFile.getFullPath();

			CorePlugin.logError(Status.INFO, "About to load REPLAY file:" + theName, null);
			
			try
			{
				// stick it in a stream
				final InputStream is = _theFile.getContents();
				final Layers theLayers = (Layers) thePlot.getAdapter(Layers.class);
				ImportReplay importer = new Debrief.ReaderWriter.Replay.ImportReplay()
				{
					// override the count-lines method.  We may only have a project-relative
					// to the data-file - and the legacy code won't be able to find the file.
					// we do, however have a stream for the input file - just count the 
					// lines in this.
					public int countLinesFor(String fName)
					{
						int lines = 0;
						try
						{
							// create ourselves a fresh stream. we create some fresh streams
							// based on this one which get closed in processing
							final InputStream lineCounterStream = _theFile.getContents();
							lines = super.countLinesInStream(lineCounterStream);
							lineCounterStream.close();
							CorePlugin.logError(Status.INFO, "Replay loader - counted:" + lines + " lines", null);
						}
						catch (IOException e)
						{
							CorePlugin.logError(Status.ERROR, "Failed to open stream for counting lines:" + fName, null);
							e.printStackTrace();
						}
						catch (CoreException e)
						{
							CorePlugin.logError(Status.ERROR, "Failed to open stream for counting lines:" + fName, null);
							e.printStackTrace();
						}
						return lines;
					}
					
				};

				// and do the import... 
				importer.importThis(thePath, is, theLayers);
			}
			catch (CoreException e)
			{
				CorePlugin.logError(org.eclipse.core.runtime.Status.ERROR,
					"Unable to open REP file for input:" + theName, e	);
			}
		
			
		}
		// ok, load the data...
		CorePlugin.logError(Status.INFO, "Successfully loaded REPLAY file", null);
	}
}

{'fraction_non_alphanumeric': 0.11618574431492451, 'fraction_numerical': 0.00038218994840435696, 'mean_word_length': 3.336371168185584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3320373', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1676, 'n_words': 368}