List of usage examples for java.io DataOutputStream flush
public void flush() throws IOException
From source file:com.igormaznitsa.jhexed.hexmap.HexFieldLayer.java
public void write(final OutputStream out) throws IOException { final DataOutputStream dout = out instanceof DataOutputStream ? (DataOutputStream) out : new DataOutputStream(out); dout.writeUTF(this.name); dout.writeUTF(this.comments); dout.writeShort(this.values.size()); for (int i = 0; i < this.values.size(); i++) { this.values.get(i).write(dout); }/*from ww w.ja v a 2s . c o m*/ dout.writeInt(this.columns); dout.writeInt(this.rows); dout.writeBoolean(this.visible); final byte[] packed = Utils.packByteArray(this.array); dout.writeInt(packed.length); dout.write(packed); dout.flush(); }
From source file:com.kyne.webby.rtk.web.WebServer.java
@SuppressWarnings("unchecked") public void printJSON(final Map<String, Object> data, final Socket clientSocket) { try {//from w w w . j a va2 s . com final DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); out.writeBytes("HTTP/1.1 200 OK\r\n"); out.writeBytes("Content-Type: application/json; charset=utf-8\r\n"); out.writeBytes("Cache-Control: no-cache \r\n"); out.writeBytes("Server: Bukkit Webby\r\n"); out.writeBytes("Connection: Close\r\n\r\n"); final JSONObject json = new JSONObject(); json.putAll(data); out.writeBytes(json.toJSONString()); out.flush(); out.close(); } catch (final SocketException e) { /* .. */ } catch (final Exception e) { LogHelper.error(e.getMessage(), e); } }
From source file:bankingclient.ChonThaoTacFrame.java
public ChonThaoTacFrame(NewOrOldAccFrame acc) { initComponents();/* w w w . j av a 2s . co m*/ jTextField1.setText(""); jLabel4.setVisible(false); jComboBox2.setVisible(false); jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); jBt_xn2.setVisible(false); this.accList = null; this.cusList = null; this.noAcc = acc; this.tt = new Thong_Tin_TK(this); this.setVisible(false); jBt_xn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (NumberUtils.isNumber(jTextField1.getText()) && (Long.parseLong(jTextField1.getText()) > 0)) { long currentMoney = 0; try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(8); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner lineScanner = new Scanner(din.readUTF()); currentMoney = Long.parseLong(lineScanner.nextLine()); System.out.println(currentMoney); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li kt ni mng,bn cn kim tra kt ni"); } if (jCheck_gt.isSelected()) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(5); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText() + "\n" + (noAcc.getCustomer())); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy ra...."); } JOptionPane.showMessageDialog(rootPane, "Gi Ti?n Thnh Cng..."); } if (jCheck_rt.isSelected()) { if ((Long.parseLong(jTextField1.getText()) <= currentMoney)) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(6); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText() + "\n" + (noAcc.getCustomer())); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra....."); } JOptionPane.showMessageDialog(rootPane, "Rt Ti?n Thnh Cng ..."); } else { System.out.println("Khng Ti?n Trong ti khon.." + currentMoney); JOptionPane.showMessageDialog(null, "Ti Khon Khng ? ? Rt ..."); } } noAcc.setVisible(true); ChonThaoTacFrame.this.setVisible(false); } else { JOptionPane.showMessageDialog(rootPane, "Cn Nhp Li S Ti?n Cn Gi Hoc Rt.."); } } }); jBt_tt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tt.setTk((String) jComboBox1.getSelectedItem()); tt.hienTenTk(); long currentMoney = 0; try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(8); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner lineScanner = new Scanner(din.readUTF()); currentMoney = Long.parseLong(lineScanner.nextLine()); // System.out.println(currentMoney); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li kt ni mng,bn cn kim tra kt ni"); } tt.hienSoDu(((Long) currentMoney).toString()); tt.setVisible(true); try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(10); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner cusScanner = new Scanner(din.readUTF()); while (cusScanner.hasNextLine()) { tt.addCus(cusScanner.nextLine()); } } catch (Exception ee) { ee.printStackTrace(); } tt.hienChuTaiKhoan(); try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(12); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner dateScanner = new Scanner(din.readUTF()); int day = Integer.parseInt(dateScanner.nextLine()); int month = Integer.parseInt(dateScanner.nextLine()); int year = Integer.parseInt(dateScanner.nextLine()); String date = (day + "-" + month + "-" + year); tt.hienNgayLapTaiKhoan(date); while (dateScanner.hasNextLine()) { // System.out.println("aaa"); tt.addGiaoDich(dateScanner.nextLine()); } tt.hienGiaoDich(); } catch (Exception ex) { ex.printStackTrace(); } ChonThaoTacFrame.this.setVisible(false); } }); jBt_xn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_tctk.isSelected()) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(7); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + (String) jComboBox2.getSelectedItem()); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra\n Thm Ch Tht Bi..."); } JOptionPane.showMessageDialog(rootPane, "Thm Ch Ti Khon Thnh Cng.."); } else { System.out.println("nothing to do..."); } } }); jBt_xtk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(11); String sent = (String) (jComboBox1.getSelectedItem()) + "\n" + noAcc.getCustomer(); dout.writeUTF(sent); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); byte check = din.readByte(); if (check == 1) { JOptionPane.showMessageDialog(rootPane, "xoa tai khoan thanh cong"); } else { JOptionPane.showMessageDialog(rootPane, "<html>xoa tai khoan <b>khong</b> thanh cong <br> chi chu chinh moi co the xoa tai khoan</html>"); } } catch (Exception ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li Kt Ni ,Vui Lng Kim Tra Li.."); } } }); /*dont touch*/ jBt_ql.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { noAcc.setVisible(true); ChonThaoTacFrame.this.setVisible(false); } }); /*dont touch*/ jComboBox1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); jComboBox2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); /*dont touch jcheckbox*/ jCheck_tctk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_tctk.isSelected()) { jLabel4.setVisible(true); jComboBox2.setVisible(true); jBt_xn2.setVisible(true); } else { jLabel4.setVisible(false); jComboBox2.setVisible(false); jBt_xn2.setVisible(false); } } }); jCheck_gt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_gt.isSelected()) { if (jCheck_rt.isSelected()) { jCheck_rt.setSelected(false); } jLabel2.setVisible(true); jLabel3.setVisible(true); jTextField1.setVisible(true); jBt_xn1.setVisible(true); } else { jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); } } }); jCheck_rt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_rt.isSelected()) { if (jCheck_gt.isSelected()) { jCheck_gt.setSelected(false); } jLabel2.setVisible(true); jLabel3.setVisible(true); jTextField1.setVisible(true); jBt_xn1.setVisible(true); } else { jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); } } }); /*dont touch jcheckbox*/ }
From source file:TimestreamsTests.java
/** * Performs HTTP post for a given URL//from w ww. j a va2 s .c om * * @param url * is the URL to get * @param params * is a URL encoded string in the form x=y&a=b... * @return a String with the contents of the get */ private Map<String, List<String>> doPost(URL url, String params) { HttpURLConnection connection; try { connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", "" + Integer.toString(params.getBytes().length)); connection.setDoInput(true); connection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(params); wr.flush(); wr.close(); Map<String, List<String>> responseHeaderFields = connection.getHeaderFields(); System.out.println(responseHeaderFields); if (responseHeaderFields.get(null).get(0).equals("HTTP/1.1 200 OK")) { InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); System.out.println(response); } return responseHeaderFields; } catch (IOException e1) { fail("Post " + url + " failed: " + e1.getLocalizedMessage()); } return null; }
From source file:com.plancake.api.client.PlancakeApiClient.java
/** * @param String request/*from w w w . jav a 2 s. c om*/ * @param String httpMethod * @return String */ private String getResponse(String request, String httpMethod) throws MalformedURLException, IOException, PlancakeApiException { if (!(httpMethod.equals("GET")) && !(httpMethod.equals("POST"))) { throw new PlancakeApiException("httpMethod must be either GET or POST"); } String urlParameters = ""; if (httpMethod == "POST") { String[] requestParts = request.split("\\?"); request = requestParts[0]; urlParameters = requestParts[1]; } URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod(httpMethod); if (httpMethod == "POST") { connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } else { connection.setRequestProperty("Content-Type", "text/plain"); } connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); connection.setUseCaches(false); connection.connect(); if (httpMethod == "POST") { DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); } StringBuffer text = new StringBuffer(); InputStreamReader in = new InputStreamReader((InputStream) connection.getContent()); BufferedReader buff = new BufferedReader(in); String line = buff.readLine(); while (line != null) { text.append(line + "\n"); line = buff.readLine(); } String response = text.toString(); if (response.length() == 0) { throw new PlancakeApiException("the response is empty"); } connection.disconnect(); return response; }
From source file:com.threeti.proxy.RequestFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String path = request.getServletPath(); String pathInfo = path.substring(path.lastIndexOf("/")); if (pathInfo == null) { response.getWriter().write("error"); } else {//from ww w. j a v a 2 s .c o m if (path.contains("/proxy")) { pathInfo = path.substring(path.lastIndexOf("/proxy") + 6); if ("POST".equals(request.getMethod())) { // POST String urlString = this.baseURL + pathInfo; logger.info(urlString); String s = this.getParams(req).substring(0, this.getParams(req).length() - 1); byte[] data = s.getBytes("utf-8"); HttpURLConnection conn = null; DataOutputStream outStream = null; URL httpUrl = new URL(urlString); conn = (HttpURLConnection) httpUrl.openConnection(); conn.setConnectTimeout(7000); conn.setReadTimeout(7000); conn.setUseCaches(false); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Charset", "utf-8"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(data.length)); outStream = new DataOutputStream(conn.getOutputStream()); outStream.write(data); outStream.flush(); if (conn.getResponseCode() == 200) { InputStream in = conn.getInputStream(); IOUtils.copy(in, response.getOutputStream()); } else { try { throw new Exception("ResponseCode=" + conn.getResponseCode()); } catch (Exception e) { e.printStackTrace(); } } } else if ("DELETE".equals(request.getMethod())) { String urlString = this.baseURL + pathInfo + "?" + this.getParams(req); logger.info(urlString); HttpURLConnection conn = null; URL url = new URL(urlString); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(7000); conn.setReadTimeout(7000); conn.setUseCaches(false); conn.setDoOutput(true); conn.setRequestMethod("DELETE"); if (conn.getResponseCode() == 200) { InputStream in = conn.getInputStream(); IOUtils.copy(in, response.getOutputStream()); } else { try { throw new Exception("ResponseCode=" + conn.getResponseCode()); } catch (Exception e) { e.printStackTrace(); } } } else { String urlString = this.baseURL + pathInfo + "?" + this.getParams(req); logger.info(urlString); URL url = new URL(urlString); InputStream input = url.openStream(); IOUtils.copy(input, response.getOutputStream()); } } else { chain.doFilter(req, res); } } }
From source file:edu.cornell.med.icb.goby.compression.HybridChunkCodec1.java
@Override public ByteArrayOutputStream encode(final Message readCollection) throws IOException { if (readCollection == null) { return null; }//w w w .j av a 2s . c o m final ByteArrayOutputStream result = new ByteArrayOutputStream(); final DataOutputStream completeChunkData = new DataOutputStream(result); final ByteArrayOutputStream hybridStreamBytes = new ByteArrayOutputStream(); final Message reducedProtoBuff = handler.compressCollection(readCollection, hybridStreamBytes); final int hybridStreamSize = hybridStreamBytes.size(); final byte[] bytes = hybridStreamBytes.toByteArray(); crc32.reset(); crc32.update(bytes); final int crcChecksum = (int) crc32.getValue(); completeChunkData.writeInt(hybridStreamSize); completeChunkData.writeInt(crcChecksum); completeChunkData.write(bytes); final ByteArrayOutputStream out = gzipCodec.encode(reducedProtoBuff); final byte[] gzipBytes = out.toByteArray(); final int gzipBytesSize = gzipBytes.length; completeChunkData.write(gzipBytes); completeChunkData.flush(); if (debug && chunkIndex % 100 == 0) { //TODO remove compression of original collection. Only useful for stat collection int originalGzipSize = gzipCodec.encode(readCollection).toByteArray().length; final int gain = originalGzipSize - (gzipBytesSize + hybridStreamSize); LOG.info(String.format( "compressed size=%d gzip size=%d (original gzip=%d) percent compressed/(compressed+gzip) %g gain=%d, %g%% ", hybridStreamSize, gzipBytesSize, originalGzipSize, 100d * ((double) hybridStreamSize) / (hybridStreamSize + gzipBytesSize), gain, gain * 100d / originalGzipSize)); } chunkIndex++; return result; }
From source file:edu.cornell.med.icb.goby.compression.HybridChunkCodec2.java
@Override public ByteArrayOutputStream encode(final Message readCollection) throws IOException { if (readCollection == null) { return null; }/* w w w . j av a 2 s .c o m*/ final ByteArrayOutputStream result = new ByteArrayOutputStream(); final DataOutputStream completeChunkData = new DataOutputStream(result); final ByteArrayOutputStream hybridStreamBytes = new ByteArrayOutputStream(); final Message reducedProtoBuff = handler.compressCollection(readCollection, hybridStreamBytes); final int hybridStreamSize = hybridStreamBytes.size(); final byte[] bytes = hybridStreamBytes.toByteArray(); crc32.reset(); crc32.update(bytes); final int crcChecksum = (int) crc32.getValue(); completeChunkData.writeInt(hybridStreamSize); completeChunkData.writeInt(crcChecksum); completeChunkData.write(bytes); final ByteArrayOutputStream out = bzip2Codec.encode(reducedProtoBuff); final byte[] gzipBytes = out.toByteArray(); final int gzipBytesSize = gzipBytes.length; completeChunkData.write(gzipBytes); completeChunkData.flush(); if (debug && chunkIndex % 100 == 0) { //TODO remove compression of original collection. Only useful for stat collection final int originalBZip2Size = bzip2Codec.encode(readCollection).toByteArray().length; final int gain = originalBZip2Size - (gzipBytesSize + hybridStreamSize); LOG.info(String.format( "compressed size=%d gzip size=%d (original gzip=%d) percent compressed/(compressed+gzip) %g gain=%d, %g%% ", hybridStreamSize, gzipBytesSize, originalBZip2Size, 100d * ((double) hybridStreamSize) / (hybridStreamSize + gzipBytesSize), gain, gain * 100d / originalBZip2Size)); } chunkIndex++; return result; }
From source file:com.envirover.spl.SPLGroungControlTest.java
@Test public void testMTMessagePipeline() { System.out.println("MT TEST: Testing MT message pipeline..."); Socket client = null;//from www. j a v a 2s .c o m DataOutputStream out = null; try { System.out.printf("MT TEST: Connecting to tcp://%s:%d", InetAddress.getLocalHost().getHostAddress(), config.getMAVLinkPort()); System.out.println(); client = new Socket(InetAddress.getLocalHost().getHostAddress(), config.getMAVLinkPort()); System.out.printf("MT TEST: Connected to tcp://%s:%d", InetAddress.getLocalHost().getHostAddress(), config.getMAVLinkPort()); System.out.println(); out = new DataOutputStream(client.getOutputStream()); MAVLinkPacket packet = getSamplePacket(); out.write(packet.encodePacket()); out.flush(); System.out.printf("MT TEST: MAVLink message sent: msgid = %d", packet.msgid); System.out.println(); Thread.sleep(5000); System.out.println("MT TEST: Complete."); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (out != null) out.close(); if (client != null) client.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:br.com.anteros.android.synchronism.communication.HttpConnectionClient.java
public MobileResponse sendReceiveData(MobileRequest mobileRequest) { sessionId = HttpConnectionSession.getInstance().getSessionId(); add(mobileRequest.getFormattedHeader(), mobileRequest.getFormatedActions()); MobileResponse mobileResponse = new MobileResponse(); try {//from ww w . j a v a 2s . c o m if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onWaitServer(); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Conectando Servidor..."); } /* * Define url e estabelece conexo */ HttpPost httpPost = new HttpPost(url); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is // established. // The default value is zero, that means the timeout is not used. HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOCKET); if (httpClient == null) httpClient = new DefaultHttpClient(httpParameters); // /* * Setar o cookie da sesso */ if ((sessionId != null) && (!"".equals(sessionId))) { httpPost.setHeader("Cookie", "JSESSIONID=" + sessionId); } httpPost.setHeader("User-Agent", "Android"); httpPost.setHeader("Accept-Encoding", "gzip"); if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Enviando requisio..."); } // ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); // /* * Escrever no output */ out.writeInt(numOption); String aux[]; for (int i = 0; i < opPOST.size(); i++) { aux = (String[]) opPOST.get(i); out.writeUTF(aux[0]); byte[] b = aux[1].getBytes(); out.writeInt(b.length); out.write(b); aux = null; } out.flush(); ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray()); entity.setContentEncoding("UTF-8"); httpPost.setEntity(entity); httpPost.addHeader("Connection", "Keep-Alive"); httpPost.addHeader("Keep-Alive", "timeout=120000"); out.close(); // if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Recebendo dados..."); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onDebugMessage("Recebendo dados conexo"); } /* * Aguardar resposta */ HttpResponse httpResponse = httpClient.execute(httpPost); List result = null; StatusLine statusLine = httpResponse.getStatusLine(); int code = statusLine.getStatusCode(); if (code != 200) { String msg = "Erro RECEBENDO resposta do Servidor " + url + " - Cdigo do Erro HTTP " + code + "-" + statusLine.getReasonPhrase(); mobileResponse.setStatus(msg); } else { if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Resposta OK !"); } /* * Ler cookie */ String tmpSessionId = null; for (Cookie c : httpClient.getCookieStore().getCookies()) { if ("JSESSIONID".equals(c.getName())) { tmpSessionId = c.getValue(); } } if (tmpSessionId != null) { sessionId = tmpSessionId; HttpConnectionSession.getInstance().setSessionId(sessionId); } // if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Lendo dados..."); } /* * Le os dados */ HttpEntity entityResponse = httpResponse.getEntity(); InputStream in = AndroidHttpClient.getUngzippedContent(entityResponse); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); String content = null; content = reader.readLine(); String line = null; while ((line = reader.readLine()) != null) { content += line; } line = ""; reader.close(); reader = null; in.close(); in = null; entityResponse.consumeContent(); entityResponse = null; // StringTokenizer messagePart = new StringTokenizer(content, "#"); content = null; if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onDebugMessage("RECEBEU dados conexo"); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Processando resposta... "); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onDebugMessage("Converteu string dados conexo"); } while (messagePart.hasMoreTokens()) { String resultData = messagePart.nextToken(); resultData = resultData.substring(resultData.indexOf("*") + 1, resultData.length()); if (result == null) result = formatData(resultData); else result.addAll(formatData(resultData)); } messagePart = null; } if (result != null) { mobileResponse.setFormattedParameters(result); result.clear(); result = null; } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onEndServer(); } } catch (SocketTimeoutException exTimeout) { exTimeout.printStackTrace(); wrapException(mobileResponse, "No foi possvel CONECTAR ao Servidor " + url + ". Verifique sua conexo e se o servidor est em funcionamento."); } catch (Exception e) { e.printStackTrace(); if ((e.getMessage() + "").contains("unreachable")) wrapException(mobileResponse, "Voc est sem acesso a internet. Verifique sua conexo. No foi possvel conectar ao servidor " + url); else wrapException(mobileResponse, "No foi possivel CONECTAR ao Servidor " + url + " " + e.getMessage()); } return mobileResponse; }