List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void consultarUsuariosEnTallerId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("3")), Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("1"))); response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (UsuarioEntity usuario : usuarios) { JSONObject obj = new JSONObject(); obj.put("id", usuario.getIdUsuario()); obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos()); list1.add(obj);/*from w w w.j a v a 2s . c o m*/ } out.print(list1); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void consultarDocentesEnTallerId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("3"))); response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (UsuarioEntity usuario : usuarios) { JSONObject obj = new JSONObject(); obj.put("id", usuario.getIdUsuario()); obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos()); list1.add(obj);/*w w w. jav a2s .c om*/ } out.print(list1); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void consultarUsuariosEnConvocatoriaId(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = new ArrayList<>(); usuarios = CtrlAdmin.obtenerUsuariosEnConvocatoria(Integer.parseInt(request.getParameter("3")), //id evento Integer.parseInt(request.getParameter("2")), //tamao tabla Integer.parseInt(request.getParameter("1"))//pagina );/* w w w . j a v a 2 s .c om*/ response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (UsuarioEntity usuario : usuarios) { JSONObject obj = new JSONObject(); obj.put("id", usuario.getIdUsuario()); obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos()); list1.add(obj); } out.print(list1); }
From source file:expect4j.ExpectUtils.java
/** * Creates an HTTP client connection to a specified HTTP server and * returns the entire response. This function simulates <code>curl * http://remotehost/url</code>./*ww w. j av a2s . c o m*/ * * @param remotehost the DNS or IP address of the HTTP server * @param url the path/file of the resource to look up on the HTTP * server * @return the response from the HTTP server * @throws Exception upon a variety of error conditions */ public static String Http(String remotehost, String url) throws Exception { Socket s = null; s = new Socket(remotehost, 80); logger.debug("Connected to " + s.getInetAddress().toString()); if (false) { // for serious connection-oriented debugging only PrintWriter out = new PrintWriter(s.getOutputStream(), false); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); System.out.println("Sending request"); out.print("GET " + url + " HTTP/1.1\r\n"); out.print("Host: " + remotehost + "\r\n"); out.print("Connection: close\r\n"); out.print("User-Agent: Expect4j\r\n"); out.print("\r\n"); out.flush(); System.out.println("Request sent"); System.out.println("Receiving response"); String line; while ((line = in.readLine()) != null) System.out.println(line); System.out.println("Received response"); if (line == null) System.exit(0); } Expect4j expect = new Expect4j(s); logger.debug("Sending HTTP request for " + url); expect.send("GET " + url + " HTTP/1.1\r\n"); expect.send("Host: " + remotehost + "\r\n"); expect.send("Connection: close\r\n"); expect.send("User-Agent: Expect4j\r\n"); expect.send("\r\n"); logger.debug("Waiting for HTTP response"); String remaining = null; expect.expect(new Match[] { new RegExpMatch("HTTP/1.[01] \\d{3} (.*)\n?\r", new Closure() { public void run(ExpectState state) { logger.trace("Detected HTTP Response Header"); // save http code String match = state.getMatch(); String parts[] = match.split(" "); state.addVar("httpCode", parts[1]); state.exp_continue(); } }), new RegExpMatch("Content-Type: (.*\\/.*)\r\n", new Closure() { public void run(ExpectState state) { logger.trace("Detected Content-Type header"); state.addVar("contentType", state.getMatch()); state.exp_continue(); } }), new EofMatch(new Closure() { // should cause entire page to be collected public void run(ExpectState state) { logger.trace("Found EOF, done receiving HTTP response"); } }), // Will cause buffer to be filled up till end new TimeoutMatch(10000, new Closure() { public void run(ExpectState state) { logger.trace("Timeout waiting for HTTP response"); } }) }); remaining = expect.getLastState().getBuffer(); // from EOF matching String httpCode = (String) expect.getLastState().getVar("httpCode"); String contentType = (String) expect.getLastState().getVar("contentType"); s.close(); return remaining; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void leerUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException { UsuarioEntity e = CtrlAdmin.leerUsuario(request.getParameter("1")); // String nombre del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("id", e.getIdUsuario()); obj.put("nombre", e.getNombres()); obj.put("apellido", e.getApellidos()); obj.put("tipoDocumento", e.gettDocumento()); obj.put("documento", e.getDocumento()); obj.put("contrasena", e.getPassword()); obj.put("rol", e.getRol()); out.print(obj); }
From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java
public static String get(String urlString, Hashtable<String, String[]> params) throws MetacatUtilException { try {/*from www .j a va2 s.c om*/ URL url = new URL(urlString); URLConnection urlConn = url.openConnection(); urlConn.setDoOutput(true); PrintWriter pw = new PrintWriter(urlConn.getOutputStream()); String queryString = paramsToQuery(params); logMetacat.debug("Sending get request: " + urlString + "?" + queryString); pw.print(queryString); pw.close(); // get the input from the request BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); return sb.toString(); } catch (MalformedURLException mue) { throw new MetacatUtilException("URL error when contacting: " + urlString + " : " + mue.getMessage()); } catch (IOException ioe) { throw new MetacatUtilException("I/O error when contacting: " + urlString + " : " + ioe.getMessage()); } }
From source file:com.spidasoftware.EclipseFormatter.Formatter.java
/** * A two-argument method that will take a fileName string and the contents of * that file (before formatted), and return a backup file. * * @param fileName string representing the name of the file. * @param before string containing the contents of that file * @return a String that represents the name of the backup file created, null otherwise. * *//*from w ww . j a va 2 s . c o m*/ public static String createBackupFile(String fileName, String before) { String nameWithDate = null; PrintWriter safety = null; try { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("MM_dd_yyyy_h_mm_ss"); String formattedDate = sdf.format(date); nameWithDate = fileName + "_BACKUP_" + formattedDate; FileWriter file = new FileWriter(nameWithDate); safety = new PrintWriter(file); safety.print(before); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (safety != null) { safety.close(); } } return nameWithDate; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void leerUsuarioId(HttpServletRequest request, HttpServletResponse response) throws IOException { UsuarioEntity e = CtrlAdmin.leerUsuarioId(Integer.parseInt(request.getParameter("1"))); // id del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("id", e.getIdUsuario()); obj.put("nombre", e.getNombres()); obj.put("apellido", e.getApellidos()); obj.put("tipoDocumento", e.gettDocumento()); obj.put("documento", e.getDocumento()); obj.put("contrasena", e.getPassword()); obj.put("rol", "" + e.getRol()); obj.put("email", e.getUsername()); out.print(obj); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerMultiplesConvocatorias(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<ConvocatoriaEntity> convocatorias = new ArrayList<>(); convocatorias = CtrlUsuario.leerMultiplesConvocatorias(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // tamao y posicin response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (ConvocatoriaEntity convocatoria : convocatorias) { JSONObject obj = new JSONObject(); obj.put("id", convocatoria.getIdConvocatoria()); obj.put("titulo", convocatoria.getNombre()); list1.add(obj);//w ww . j ava2 s . c om } out.print(list1); }
From source file:com.dumbster.smtp.SimpleSmtpServer.java
/** * Send response to client.//from w ww . j ava 2 s . c o m * * @param out * socket output stream * @param smtpResponse * response object */ private static void sendResponse(PrintWriter out, SmtpResponse smtpResponse) { if (smtpResponse.getCode() > 0) { int code = smtpResponse.getCode(); String message = smtpResponse.getMessage(); out.print(code + " " + message + "\r\n"); out.flush(); } }