Java Code Examples for java.io.PrintWriter.checkError()

The following are Jave code examples for showing how to use checkError() of the java.io.PrintWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: org.alloytools.alloy   File: StaticThemeReaderWriter.java   View Source Code Vote up 7 votes
/** Returns the String representation of an AlloyNodeElement's settings. */
private static String writeNodeViz(VizState view, VizState defaultView, AlloyNodeElement x) throws IOException {
	StringWriter sw = new StringWriter();
	PrintWriter out = new PrintWriter(sw);
	writeBool(out, "visible", view.nodeVisible.get(x), defaultView.nodeVisible.get(x));
	writeBool(out, "hideunconnected", view.hideUnconnected.get(x), defaultView.hideUnconnected.get(x));
	if (x == null || x instanceof AlloySet) {
		AlloySet s = (AlloySet) x;
		writeBool(out, "showlabel", view.showAsLabel.get(s), defaultView.showAsLabel.get(s));
		writeBool(out, "showinattr", view.showAsAttr.get(s), defaultView.showAsAttr.get(s));
	}
	if (x == null || x instanceof AlloyType) {
		AlloyType t = (AlloyType) x;
		writeBool(out, "numberatoms", view.number.get(t), defaultView.number.get(t));
	}
	writeDotStyle(out, view.nodeStyle.get(x), defaultView.nodeStyle.get(x));
	writeDotShape(out, view.shape.get(x), defaultView.shape.get(x));
	writeDotColor(out, view.nodeColor.get(x), defaultView.nodeColor.get(x));
	if (x != null && !view.label.get(x).equals(defaultView.label.get(x)))
		Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
	if (out.checkError())
		throw new IOException("PrintWriter IO Exception!");
	return sw.toString();
}
 
Example 2
Project: org.alloytools.alloy   File: StaticThemeReaderWriter.java   View Source Code Vote up 7 votes
/** Returns the String representation of an AlloyRelation's settings. */
private static String writeEdgeViz(VizState view, VizState defaultView, AlloyRelation x) throws IOException {
	StringWriter sw = new StringWriter();
	PrintWriter out = new PrintWriter(sw);
	writeDotColor(out, view.edgeColor.get(x), defaultView.edgeColor.get(x));
	writeDotStyle(out, view.edgeStyle.get(x), defaultView.edgeStyle.get(x));
	writeBool(out, "visible", view.edgeVisible.get(x), defaultView.edgeVisible.get(x));
	writeBool(out, "merge", view.mergeArrows.get(x), defaultView.mergeArrows.get(x));
	writeBool(out, "layout", view.layoutBack.get(x), defaultView.layoutBack.get(x));
	writeBool(out, "attribute", view.attribute.get(x), defaultView.attribute.get(x));
	writeBool(out, "constraint", view.constraint.get(x), defaultView.constraint.get(x));
	if (view.weight.get(x) != defaultView.weight.get(x))
		out.write(" weight=\"" + view.weight.get(x) + "\"");
	if (x != null && !view.label.get(x).equals(defaultView.label.get(x)))
		Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
	if (out.checkError())
		throw new IOException("PrintWriter IO Exception!");
	return sw.toString();
}
 
Example 3
Project: org.alloytools.alloy   File: A4SolutionWriter.java   View Source Code Vote up 7 votes
/**
 * If this solution is a satisfiable solution, this method will write it out
 * in XML format.
 */
static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Iterable<Func> extraSkolems,
		Map<String,String> sources) throws Err {
	if (!sol.satisfiable())
		throw new ErrorAPI("This solution is unsatisfiable.");
	try {
		Util.encodeXMLs(out, "<alloy builddate=\"", Version.buildDate(), "\">\n\n");
		new A4SolutionWriter(rep, sol, sol.getAllReachableSigs(), sol.getBitwidth(), sol.getMaxSeq(),
				sol.getOriginalCommand(), sol.getOriginalFilename(), out, extraSkolems);
		if (sources != null)
			for (Map.Entry<String,String> e : sources.entrySet()) {
				Util.encodeXMLs(out, "\n<source filename=\"", e.getKey(), "\" content=\"", e.getValue(), "\"/>\n");
			}
		out.print("\n</alloy>\n");
	} catch (Throwable ex) {
		if (ex instanceof Err)
			throw (Err) ex;
		else
			throw new ErrorFatal("Error writing the solution XML file.", ex);
	}
	if (out.checkError())
		throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 4
Project: myfaces-trinidad   File: CSSGenerationUtils.java   View Source Code Vote up 7 votes
/**
 * outputs the footer for a css file
 * @param out
 * @param styleSheetName
 * @param compressStyles
 * @param fileSelectorsWritten
 */
private static void _endCssFile(PrintWriter out, String styleSheetName, boolean compressStyles, int fileSelectorsWritten)
{
  if (!compressStyles)
  {
    out.print("/* The number of CSS selectors in this file is ");
    out.print(fileSelectorsWritten);
    out.println(" */");
  }

  if (out.checkError())
  {
    _LOG.severe("Error writing stylesheet:" + styleSheetName);
  }

  out.close();
}
 
Example 5
Project: Tarski   File: StaticThemeReaderWriter.java   View Source Code Vote up 7 votes
/** Returns the String representation of an AlloyNodeElement's settings. */
private static String writeNodeViz(VizState view, VizState defaultView, AlloyNodeElement x) throws IOException {
   StringWriter sw=new StringWriter();
   PrintWriter out=new PrintWriter(sw);
   writeBool(out, "visible",         view.nodeVisible.get(x),     defaultView.nodeVisible.get(x));
   writeBool(out, "hideunconnected", view.hideUnconnected.get(x), defaultView.hideUnconnected.get(x));
   if (x==null || x instanceof AlloySet) {
      AlloySet s=(AlloySet)x;
      writeBool(out, "showlabel",  view.showAsLabel.get(s), defaultView.showAsLabel.get(s));
      writeBool(out, "showinattr", view.showAsAttr.get(s),  defaultView.showAsAttr.get(s));
   }
   if (x==null || x instanceof AlloyType) {
      AlloyType t=(AlloyType)x;
      writeBool(out, "numberatoms",     view.number.get(t),  defaultView.number.get(t));
   }
   writeDotStyle(out, view.nodeStyle.get(x), defaultView.nodeStyle.get(x));
   writeDotShape(out, view.shape.get(x),     defaultView.shape.get(x));
   writeDotColor(out, view.nodeColor.get(x), defaultView.nodeColor.get(x));
   if (x!=null && !view.label.get(x).equals(defaultView.label.get(x)))
      Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
   if (out.checkError()) throw new IOException("PrintWriter IO Exception!");
   return sw.toString();
}
 
Example 6
Project: Tarski   File: StaticThemeReaderWriter.java   View Source Code Vote up 7 votes
/** Returns the String representation of an AlloyRelation's settings. */
private static String writeEdgeViz(VizState view, VizState defaultView, AlloyRelation x) throws IOException {
   StringWriter sw=new StringWriter();
   PrintWriter out=new PrintWriter(sw);
   writeDotColor(out, view.edgeColor.get(x), defaultView.edgeColor.get(x));
   writeDotStyle(out, view.edgeStyle.get(x), defaultView.edgeStyle.get(x));
   writeBool(out, "visible",   view.edgeVisible.get(x),  defaultView.edgeVisible.get(x));
   writeBool(out, "merge",     view.mergeArrows.get(x),  defaultView.mergeArrows.get(x));
   writeBool(out, "layout",    view.layoutBack.get(x),   defaultView.layoutBack.get(x));
   writeBool(out, "attribute", view.attribute.get(x),    defaultView.attribute.get(x));
   writeBool(out, "constraint",view.constraint.get(x),   defaultView.constraint.get(x));
   if (view.weight.get(x) != defaultView.weight.get(x))  out.write(" weight=\"" + view.weight.get(x) + "\"");
   if (x!=null && !view.label.get(x).equals(defaultView.label.get(x)))
      Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
   if (out.checkError()) throw new IOException("PrintWriter IO Exception!");
   return sw.toString();
}
 
Example 7
Project: Tarski   File: StaticThemeReaderWriter.java   View Source Code Vote up 7 votes
/** Returns the String representation of an AlloyNodeElement's settings. */
private static String writeNodeViz(VizState view, VizState defaultView, AlloyNodeElement x) throws IOException {
   StringWriter sw=new StringWriter();
   PrintWriter out=new PrintWriter(sw);
   writeBool(out, "visible",         view.nodeVisible.get(x),     defaultView.nodeVisible.get(x));
   writeBool(out, "hideunconnected", view.hideUnconnected.get(x), defaultView.hideUnconnected.get(x));
   if (x==null || x instanceof AlloySet) {
      AlloySet s=(AlloySet)x;
      writeBool(out, "showlabel",  view.showAsLabel.get(s), defaultView.showAsLabel.get(s));
      writeBool(out, "showinattr", view.showAsAttr.get(s),  defaultView.showAsAttr.get(s));
   }
   if (x==null || x instanceof AlloyType) {
      AlloyType t=(AlloyType)x;
      writeBool(out, "numberatoms",     view.number.get(t),  defaultView.number.get(t));
   }
   writeDotStyle(out, view.nodeStyle.get(x), defaultView.nodeStyle.get(x));
   writeDotShape(out, view.shape.get(x),     defaultView.shape.get(x));
   writeDotColor(out, view.nodeColor.get(x), defaultView.nodeColor.get(x));
   if (x!=null && !view.label.get(x).equals(defaultView.label.get(x)))
      Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
   if (out.checkError()) throw new IOException("PrintWriter IO Exception!");
   return sw.toString();
}
 
Example 8
Project: Tarski   File: StaticThemeReaderWriter.java   View Source Code Vote up 7 votes
/** Returns the String representation of an AlloyRelation's settings. */
private static String writeEdgeViz(VizState view, VizState defaultView, AlloyRelation x) throws IOException {
   StringWriter sw=new StringWriter();
   PrintWriter out=new PrintWriter(sw);
   writeDotColor(out, view.edgeColor.get(x), defaultView.edgeColor.get(x));
   writeDotStyle(out, view.edgeStyle.get(x), defaultView.edgeStyle.get(x));
   writeBool(out, "visible",   view.edgeVisible.get(x),  defaultView.edgeVisible.get(x));
   writeBool(out, "merge",     view.mergeArrows.get(x),  defaultView.mergeArrows.get(x));
   writeBool(out, "layout",    view.layoutBack.get(x),   defaultView.layoutBack.get(x));
   writeBool(out, "attribute", view.attribute.get(x),    defaultView.attribute.get(x));
   writeBool(out, "constraint",view.constraint.get(x),   defaultView.constraint.get(x));
   if (view.weight.get(x) != defaultView.weight.get(x))  out.write(" weight=\"" + view.weight.get(x) + "\"");
   if (x!=null && !view.label.get(x).equals(defaultView.label.get(x)))
      Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
   if (out.checkError()) throw new IOException("PrintWriter IO Exception!");
   return sw.toString();
}
 
Example 9
Project: org.alloytools.alloy   File: A4Solution.java   View Source Code Vote up 6 votes
/** Helper method to write out a full XML file. */
public void writeXML(A4Reporter rep, PrintWriter writer, Iterable<Func> macros, Map<String,String> sourceFiles)
		throws Err {
	A4SolutionWriter.writeInstance(rep, this, writer, macros, sourceFiles);
	if (writer.checkError())
		throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 10
Project: org.alloytools.alloy   File: A4SolutionWriter.java   View Source Code Vote up 6 votes
/**
 * Write the metamodel as &lt;instance&gt;..&lt;/instance&gt; in XML format.
 */
public static void writeMetamodel(ConstList<Sig> sigs, String originalFilename, PrintWriter out) throws Err {
	try {
		new A4SolutionWriter(null, null, sigs, 4, 4, "show metamodel", originalFilename, out, null);
	} catch (Throwable ex) {
		if (ex instanceof Err)
			throw (Err) ex;
		else
			throw new ErrorFatal("Error writing the solution XML file.", ex);
	}
	if (out.checkError())
		throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 11
Project: convertigo-engine   File: JsseSecureSocketImpl.java   View Source Code Vote up 6 votes
@SuppressWarnings("unused")
private void sendPobiRequest(Socket socket) throws IOException {
	Engine.logEmulators.trace("[JsseSesureSocketImpl] Retrieving Pobi Fiben Home page...");
    PrintWriter out = new PrintWriter(
			  new BufferedWriter(
			  new OutputStreamWriter(
    				  socket.getOutputStream())));
    out.println("GET " + "/fiben/home.aspx" + " HTTP/1.0");
    out.println();
    out.flush();

    if (out.checkError())
    	Engine.logEmulators.trace("[JsseSesureSocketImpl] java.io.PrintWriter error");

    BufferedReader in = new BufferedReader(
			    new InputStreamReader(
			    socket.getInputStream()));

    String inputLine;
    while ((inputLine = in.readLine()) != null)
    	Engine.logEmulators.trace("[JsseSesureSocketImpl] "+inputLine);

    in.close();
    out.close();
    socket.close();
    
    throw new IOException("Socket has been closed");
}
 
Example 12
Project: Tarski   File: TranslateKodkodToJava.java   View Source Code Vote up 6 votes
/** Given a Kodkod formula node, return a Java program that (when compiled and executed) would solve that formula.
 *
 * <p> Requirement: atoms must be String objects (since we cannot possibly
 * output a Java source code that can re-generate arbitrary Java objects).
 *
 * @param formula - the formula to convert
 * @param bitwidth - the integer bitwidth
 * @param atoms - an iterator over the set of all atoms
 * @param bounds - the Kodkod bounds object to use
 * @param atomMap - if nonnull, it is used to map the atom name before printing
 */
public static String convert
(Formula formula, int bitwidth, Iterable<String> atoms, Bounds bounds, Map<Object,String> atomMap) {
    StringWriter string=new StringWriter();
    PrintWriter file=new PrintWriter(string);
    new TranslateKodkodToJava(file, formula, bitwidth, atoms, bounds, atomMap);
    if (file.checkError()) {
        return ""; // shouldn't happen
    } else {
        return string.toString();
    }
}
 
Example 13
Project: Tarski   File: A4SolutionWriter.java   View Source Code Vote up 6 votes
/** If this solution is a satisfiable solution, this method will write it out in XML format. */
static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Iterable<Func> extraSkolems, Map<String,String> sources) throws Err {
    if (!sol.satisfiable()) throw new ErrorAPI("This solution is unsatisfiable.");
    try {
        Util.encodeXMLs(out, "<alloy builddate=\"", Version.buildDate(), "\">\n\n");
        new A4SolutionWriter(rep, sol, sol.getAllReachableSigs(), sol.getBitwidth(), sol.getMaxSeq(), sol.getOriginalCommand(), sol.getOriginalFilename(), out, extraSkolems);
        if (sources!=null) for(Map.Entry<String,String> e: sources.entrySet()) {
            Util.encodeXMLs(out, "\n<source filename=\"", e.getKey(), "\" content=\"", e.getValue(), "\"/>\n");
        }
        out.print("\n</alloy>\n");
    } catch(Throwable ex) {
        if (ex instanceof Err) throw (Err)ex; else throw new ErrorFatal("Error writing the solution XML file.", ex);
    }
    if (out.checkError()) throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 14
Project: Tarski   File: A4SolutionWriter.java   View Source Code Vote up 6 votes
/** Write the metamodel as &lt;instance&gt;..&lt;/instance&gt; in XML format. */
public static void writeMetamodel(ConstList<Sig> sigs, String originalFilename, PrintWriter out) throws Err {
    try {
        new A4SolutionWriter(null, null, sigs, 4, 4, "show metamodel", originalFilename, out, null);
    } catch(Throwable ex) {
        if (ex instanceof Err) throw (Err)ex; else throw new ErrorFatal("Error writing the solution XML file.", ex);
    }
    if (out.checkError()) throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 15
Project: SparkSeq   File: KBestHaplotypeFinder.java   View Source Code Vote up 6 votes
/**
 * Print a DOT representation of search graph.
 *
 * @param file file where to print the DOT representation to.
 *
 * @throws IllegalArgumentException if {@code file} is {@code null}.
 * @throws FileNotFoundException if {@code file} cannot be created or written.
 * @throws IllegalStateException if there was some trouble when writing the DOT representation.
 */
public void printDOT(final File file) throws FileNotFoundException {
    if (file == null)
        throw new IllegalArgumentException("the output file cannot be null");
    final PrintWriter out = new PrintWriter(file);
    printDOT(out);
    if (out.checkError())
        throw new IllegalStateException("error occurred while writing k-best haplotype search graph into file '"
                + file.getAbsolutePath() + "'");
    out.close();
}
 
Example 16
Project: org.alloytools.alloy   File: A4Solution.java   View Source Code Vote up 5 votes
/** Helper method to write out a full XML file. */
public void writeXML(PrintWriter writer, Iterable<Func> macros, Map<String,String> sourceFiles) throws Err {
	A4SolutionWriter.writeInstance(null, this, writer, macros, sourceFiles);
	if (writer.checkError())
		throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 17
Project: Tarski   File: A4Solution.java   View Source Code Vote up 5 votes
/** Helper method to write out a full XML file. */
public void writeXML(PrintWriter writer, Iterable<Func> macros, Map<String,String> sourceFiles) throws Err {
    A4SolutionWriter.writeInstance(null, this, writer, macros, sourceFiles);
    if (writer.checkError()) throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 18
Project: Tarski   File: A4Solution.java   View Source Code Vote up 5 votes
/** Helper method to write out a full XML file. */
public void writeXML(A4Reporter rep, PrintWriter writer, Iterable<Func> macros, Map<String,String> sourceFiles) throws Err {
    A4SolutionWriter.writeInstance(rep, this, writer, macros, sourceFiles);
    if (writer.checkError()) throw new ErrorFatal("Error writing the solution XML file.");
}
 
Example 19
Project: Virtual-IoT-Server   File: WorkerRunnable.java   View Source Code Vote up 5 votes
public void run() {//run method is called

    //Create message acceptor thread
    MessageAcceptor ma = new MessageAcceptor(clientSocket);//ma is a message acceptor and it takes in the clientSocket parameter
    new Thread(ma).start();//ma is a new thread and calls on the start method

    boolean running = true;//running is a true boolean
    try {
      while (running) {//try that while running is going, the pw will be a new socket from the output message
        if (running) {

          //Create a writer to pass messages from client to server
          PrintWriter pw = new PrintWriter(clientSocket.getOutputStream());

          //for reading input text
          BufferedReader msgTaker = new BufferedReader(new InputStreamReader(System.in));//msgTaker reads through the input stream
          System.out.println("");//print out a blank statement
          long end=System.currentTimeMillis()+1500;//end prints out the time +1500
          //non-blocking text input such that the user is given some time to enter a message
          String message = "";
          while((System.currentTimeMillis()<end)) {//while the time is less than the end
            if (msgTaker.ready())//if the buffered reader calls on the ready method
            message += msgTaker.readLine();//concatinate the following
          }

          //Message handling - non blocking
          if (message.equals("")) {//if the message is still blank
            System.out.println("No input on socket: " + clientSocket.getLocalAddress().toString());
          }//the following will print out
          else {
            System.out.println("The message is " + message + " on socket " + clientSocket.getLocalAddress().toString());
          }
          pw.println(message);

          //Check if client disconnected
          if (pw.checkError()) {//if the pw calls on the error message
            running = false;//running is false
            System.out.println("Cliented disconnected");
          }

          pw.flush();//flush out the print writer
        }
      }
      clientSocket.close();//close connection with the client socket
    } catch (IOException ioe) {//catch the following exception
      ioe.printStackTrace();//print stack trace
      System.out.println("Error connecting");//error messge will pop up
    }
  }
 
Example 20
Project: org.alloytools.alloy   File: TranslateKodkodToJava.java   View Source Code Vote up 4 votes
/**
 * Given a Kodkod formula node, return a Java program that (when compiled
 * and executed) would solve that formula.
 * <p>
 * Requirement: atoms must be String objects (since we cannot possibly
 * output a Java source code that can re-generate arbitrary Java objects).
 *
 * @param formula - the formula to convert
 * @param bitwidth - the integer bitwidth
 * @param atoms - an iterator over the set of all atoms
 * @param bounds - the Kodkod bounds object to use
 * @param atomMap - if nonnull, it is used to map the atom name before
 *            printing
 */
public static String convert(Formula formula, int bitwidth, Iterable<String> atoms, Bounds bounds,
		Map<Object,String> atomMap) {
	StringWriter string = new StringWriter();
	PrintWriter file = new PrintWriter(string);
	new TranslateKodkodToJava(file, formula, bitwidth, atoms, bounds, atomMap);
	if (file.checkError()) {
		return ""; // shouldn't happen
	} else {
		return string.toString();
	}
}