Java Code Examples for com.sun.xml.internal.fastinfoset.Encoder

Following code examples demonstrate how to use com.sun.xml.internal.fastinfoset.Encoderfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.sun.xml.internal.fastinfoset.Encoderand various code implementation of this class.

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String keyWords = null;
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		try {
			
			keyWords = request.getParameter("keyWords");
		} catch (Exception e) {

			System.out.println("获取关键字异常");
			e.printStackTrace();
			
			request.setAttribute("judge", "false");
			request.setAttribute("text", "错误的操作");
			request.setAttribute("URL", "../FirstPage/FirstPage.jsp");
			request.getRequestDispatcher("../Tips/ErrorTips.jsp").forward(
					request, response);
			return;
		}
		
		keyWords = URLEncoder.encode(keyWords, "UTF-8");
		response.sendRedirect("../Product/ProductSearch.jsp?keyWords=" + keyWords);
		return;
	} 


    public static void main(String[] args) {
        Request request = new Request();
        request.setCommand("HELLO");
        request.setCommandLength(request.getCommand().length());
        request.setEncode(Encoder.UTF_8.getBytes());

        try {
            Socket client = new Socket("127.0.0.1", 4567);
            OutputStream outputStream = client.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

	public static void main(String[] args) {
		
		
		
		String asd=URLEncoder.encode("");
		System.out.println(asd);
		String asdasd=URLDecoder.decode("%E5%88%98%E5%85%AC%E5%B2%9B");
		System.out.println(asdasd);
		
		
		
	} 

   	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   		String ddid = request.getParameter("ddid");
   		String sql = "SELECT * from dingdan where id="+ddid;
   		DBUtil util = new DBUtil();
   		Connection conn = util.openConnection();
   		String result = "";
   		try {
   			PreparedStatement pstmt = conn.prepareStatement(sql);
   			ResultSet rs = pstmt.executeQuery();
   			while(rs.next()) {
   				int ddid2 = rs.getInt("id");
   				String phone = rs.getString("phone");
   				String address = URLEncoder.encode(rs.getString("address"));
   				String totle = rs.getString("totle");
   				result+=ddid2;
   				result+=",";
   				result+=phone;
   				result+=",";
   				result+=address;
   				result+=",";
   				result+=totle;
   			}
   		}catch (SQLException e) {
   			result = "0";
   			e.printStackTrace();
   		} finally {
   			util.closeConn(conn);
   		}	
   		System.out.println(result);
   		PrintWriter out = response.getWriter();
   		out.print(result);
   	} 

    public static void main(String[] args) throws UnsupportedEncodingException, MalformedURLException {
        System.out.println("myurl = " + myurl);
        Base64.Encoder urlEncoder = Base64.getUrlEncoder();
        byte[] encodedMyurl = urlEncoder.encode(myurl.toString().getBytes(Encoder.UTF_8));
        System.out.println("Base64 Encoded URL : " + new String(encodedMyurl,"UTF-8"));

        System.out.println("mystr = " + mystr);
        Base64.Encoder encoder = Base64.getEncoder();
        byte[] encodedMystr = encoder.encode(mystr.getBytes());
        System.out.println("Base64 Encoded Str : " + new String(encodedMystr,"UTF-8"));
    } 

			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
				log.info("---------");
				String result = "";
				String message = new String(body, Encoder.UTF_8);
				int n = Integer.parseInt(message);
				result += a(n);
				log.info("接收到消息:{},consumerTag:{},envelope:{}",message,consumerTag,envelope);
				AMQP.BasicProperties properties1 = new AMQP.BasicProperties().builder()
						.correlationId(properties.getCorrelationId())
						.build();
				channel.basicPublish("",properties.getReplyTo(),properties1,result.getBytes());
			} 

	public static void main(String[] args) {
		String psd = "123" + "moblie";
		encoder(psd);
	} 

	private static void encoder(String psd) {
		StringBuffer stringBuffer = new StringBuffer();
		try {
			MessageDigest digest = MessageDigest.getInstance("MD5");
			byte[] bs = digest.digest(psd.getBytes());

			for (byte b : bs) {
				int i = b & 0xff;
				String hexString = Integer.toHexString(i);
				if (hexString.length() < 2) {
					hexString = "0" + hexString;
				}

				stringBuffer.append(hexString);
			}
			System.out.println(stringBuffer);

		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

	} 

        while (true) {
            Socket client = server.accept();

            InputStream input = client.getInputStream();
            Request request = ProtocolUtil.readRequest(input);

            OutputStream output = client.getOutputStream();
            Response response = new Response();
            response.setEncode(Encoder.UTF_8.getBytes()[0]);
            if ("HELLO".equals(request.getCommand()))
                response.setResponse("hello!");
            else
                response.setResponse("bye bye!");
            response.setResponseLength(response.getResponse().length());

            ProtocolUtil.writeResponse(output, response);

            Thread.sleep(2000);
            System.out.println(client.isClosed());
        } 

    public static void writeResponse(OutputStream outputStream, Response response) {
        try {
            outputStream.write(response.getEncode());
            if (Encoder.UTF_8.getBytes() == response.getEncode()) {
                outputStream.write(response.getResponse().getBytes("UTF-8"));
            } else {
                outputStream.write(response.getResponse().getBytes("GBK"));
            }
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    public static Request readRequest(InputStream input) throws IOException {

        byte[] encodeByte = new byte[1];
        input.read(encodeByte);

        byte[] commandLength = new byte[4];
        input.read(commandLength);
        byte[] commandBytes = new byte[commandLen];
        input.read(commandBytes);
        String command = "";
        if (Encoder.UTF_8.getBytes() == encodeByte) {
            command = new String(commandBytes, "UTF-8");
        } else {
            command = new String(commandBytes, "GBK");
        }
        Request request = new Request();
        request.setCommand(command);
        request.setEncode(encodeByte);
        request.setCommandLength(commandLen);
        return request;
    } 

Advertisement
Javadoc
Abstract encoder for developing concrete encoders. Concrete implementations extending Encoder will u

tilize methods on Encoder to encode XML infoset according to the Fast Infoset standard. It is the responsibility of the concrete implementation to ensure that methods are invoked in the correct order to produce a valid fast infoset document.

This class extends org.sax.xml.DefaultHandler so that concrete SAX implementations can be used with javax.xml.parsers.SAXParser and the parse methods that take org.sax.xml.DefaultHandler as a parameter.

Buffering of octets that are written to an java.io.OutputStream is supported in a similar manner to a java.io.BufferedOutputStream. Combining buffering with encoding enables better performance.

More than one fast infoset document may be encoded to the java.io.OutputStream.

Read More
Advertisement