public static NamedPointSet fromFile( File f, ImagePlus imagePlus, String imageFilename ) throws PointsFileException { try { return fromBufferedReader( new BufferedReader( new FileReader(f) ), imagePlus, imageFilename ); } catch( FileNotFoundException e ) { throw new PointsFileException( "Couldn't find the file: "+f.getAbsolutePath() ); } }
public static NamedPointSet fromBufferedReader( BufferedReader br, ImagePlus imagePlus, String imageFilename ) throws PointsFileException { StringBuffer result = new StringBuffer( "" ); String line = null; try { while( true ) { line = br.readLine(); if( line == null ) return fromString( result.toString(), imagePlus, imageFilename ); else { result.append( line ); result.append( "\n" ); } } } catch( IOException e ) { throw new PointsFileException( "There was an IOException while reading points file data: " + e ); } }
public static NamedPointSet fromFile( String pointsFilename, ImagePlus imagePlus, String imageFilename ) throws PointsFileException { File f = new File( pointsFilename ); if( ! f.exists() ) { throw new PointsFileException( "File not found: " + pointsFilename ); } return fromFile( f, imagePlus, imageFilename ); }
return nps; } catch( javax.xml.parsers.ParserConfigurationException e ) { throw new PointsFileException( "There was a ParserConfigurationException when trying to parse as XML: " + e ); } catch( SAXException e ) { throw new PointsFileException( "BUG: FileNotFoundException while parsing XML from a String: " + e ); } catch( IOException e ) { throw new PointsFileException( "BUG: IOException while parsing XML from a String: " + e ); for( String [] a : l ) { if( a.length != 4 ) throw new PointsFileException( "There must be 4 fields per line of the tab-separated values file" ); String xString = a[0]; String yString = a[1]; set = true; } else { throw new PointsFileException( "In tab-separated format, the first three columns must all be empty or all be numbers" ); continue; } else { throw new PointsFileException( "Couldn't parse the points file; the problematic line is '" + line + "'" ); return nps; } catch( NumberFormatException e ) { throw new PointsFileException( "Failed to load the points file by any method; the last error was: " + e ); } catch( PointsFileException e ) { throw new PointsFileException( "Failed to load the points file by any method; the last error was: " + e );
public static NamedPointSet forImage( ImagePlus imagePlus, String imageFilename ) throws PointsFileException { String [] possibleExtensions = { ".points.xml", ".points.R", ".points" }; int lastDot = imageFilename.lastIndexOf( "." ); String withoutExtension = null; if( lastDot >= 0 ) withoutExtension = imageFilename.substring( 0, lastDot ); for( String extension : possibleExtensions ) { for( int i = 0; i < 2; ++i ) { String candidateFilename = null; if( i == 0 && lastDot >= 0 ) { candidateFilename = withoutExtension + extension; } else if( i == 1 ) { candidateFilename = imageFilename + extension; } try { return fromFile( candidateFilename, imagePlus, imageFilename ); } catch( PointsFileException e ) { } } } throw new PointsFileException( "None of the points filenames corresponding to '" + imageFilename + "' could be loaded." ); }
public static NamedPointSet forImage( ImagePlus imagePlus ) throws PointsFileException { FileInfo info = imagePlus.getOriginalFileInfo(); if( info == null ) throw new PointsFileException( "Could not find original file for the image: " + imagePlus.getTitle() ); String fileName = info.fileName; String url = info.url; String directory = info.directory; File f = new File( directory, fileName ); return NamedPointSet.forImage( imagePlus, f.getAbsolutePath() ); }