private void insertRecord(String line) throws FormatException { String[] fields = line.split(","); if (fields.length < 9) throw new FormatException( "Too few columns in sample sheet. Expecing at least 9 but found " + fields.length + ". Line: " + line); // Format is CSV with these columns: // "FCID","Lane","SampleID","SampleRef","Index","Description","Control","Recipe","Operator" // All text fields are quoted (all except Lane) // remove external quotes and whitespace from all string fields (even spaces within the quotes) for (int i = 0; i < fields.length; ++i) { quoteMatcher.reset(fields[i]); fields[i] = quoteMatcher.replaceAll("").trim(); } Entry entry; try { entry = Entry.createEntry(fields); } catch (IllegalArgumentException e) { throw new FormatException(e.getMessage() + ". Line: " + line); } table.add(entry); }
public int addToTable(String line) { String[] a = line.split(splitToken); try { return addToTable(a); } catch (IllegalArgumentException e) { String msg = String.format("\"%s\" -> '%s'", e.getMessage(), line); throw new IllegalArgumentException(msg, e); } }
/** * Does real work; separated out so it can be efficiently called from subclass. * * @param params Request parameters * @param doc MathML as DOM document * @param result Initialised result object with blank fields * @param start Start time of request (milliseconds since epoch) * @return Return result * @throws IOException Any error creating image file */ protected MathsImageReturn getImage( MathsImageParams params, Document doc, MathsImageReturn result, long start) throws IOException { initContext(); Color fg; try { fg = convertRgb(params.getRgb()); } catch (IllegalArgumentException e) { result.setError(e.getMessage()); return result; } if (SHOWPERFORMANCE) { System.err.println("Setup: " + (System.currentTimeMillis() - start)); } // Parse XML to JEuclid document DocumentElement document; preprocessForJEuclid(doc); document = DOMBuilder.getInstance().createJeuclidDom(doc); if (SHOWPERFORMANCE) { System.err.println("Parse: " + (System.currentTimeMillis() - start)); } // Set layout options LayoutContextImpl layout = new LayoutContextImpl(LayoutContextImpl.getDefaultLayoutContext()); layout.setParameter(Parameter.ANTIALIAS, Boolean.TRUE); // This size is hardcoded to go well with our default text size // and be one of the sizes that doesn't look too horrible. layout.setParameter(Parameter.MATHSIZE, params.getSize() * 15f); layout.setParameter(Parameter.SCRIPTSIZEMULTIPLIER, 0.86667f); layout.setParameter(Parameter.MATHCOLOR, fg); // These fonts are included with the JEuclid build so ought to work layout.setParameter( Parameter.FONTS_SERIF, Arrays.asList(new String[] {"DejaVu Serif", "Quivira"})); layout.setParameter(Parameter.FONTS_SCRIPT, Arrays.asList(new String[] {"Allura"})); layout.setParameter(Parameter.FONTS_SANSSERIF, "DejaVu Sans"); layout.setParameter(Parameter.FONTS_MONOSPACED, "DejaVu Sans Mono"); if (SHOWPERFORMANCE) { System.err.println("Layout: " + (System.currentTimeMillis() - start)); } // Layout equation JEuclidView view = new JEuclidView(document, layout, context); float ascent = view.getAscentHeight(); float descent = view.getDescentHeight(); float width = view.getWidth(); if (SHOWPERFORMANCE) { System.err.println("View: " + (System.currentTimeMillis() - start)); } // Create new image to hold it int pixelWidth = Math.max(1, (int) Math.ceil(width)), pixelHeight = Math.max(1, (int) Math.ceil(ascent + descent)); BufferedImage image = new BufferedImage(pixelWidth, pixelHeight, BufferedImage.TYPE_INT_ARGB); if (SHOWPERFORMANCE) { System.err.println("Image: " + (System.currentTimeMillis() - start)); } view.draw(image.createGraphics(), 0, ascent); if (SHOWPERFORMANCE) { System.err.println("Draw: " + (System.currentTimeMillis() - start)); } ByteArrayOutputStream output = new ByteArrayOutputStream(); ImageIO.write(image, "png", output); if (SHOWPERFORMANCE) { System.err.println("PNG: " + (System.currentTimeMillis() - start)); } // Save results result.setImage(output.toByteArray()); result.setBaseline(BigInteger.valueOf(image.getHeight() - (int) Math.round(ascent))); result.setOk(true); if (SHOWPERFORMANCE) { System.err.println("End: " + (System.currentTimeMillis() - start)); } return result; }