All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tsc9526.monalisa.tools.servlet.TrimHeadServletWrapper Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package com.tsc9526.monalisa.tools.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class TrimHeadServletWrapper extends HttpServletResponseWrapper{
	private PrintWriter pw=null;
	
	public TrimHeadServletWrapper(HttpServletResponse response) {
		super(response);
	}	
	
	public PrintWriter getWriter() throws IOException{
		if(pw==null){
			pw=new HeadTrimWriter(super.getWriter(),true);
		}
		return pw;
	}
	
	
	public class HeadTrimWriter extends PrintWriter {
		private long writeLength=0L;
		
		public HeadTrimWriter(PrintWriter out) {
			super(out);			
		}
		
		public HeadTrimWriter(PrintWriter out,boolean autoFlush) {
			super(out,autoFlush);			
		}
	 
		public void write(int c) {
			if(writeLength==0 && c=='\n'){
				
			}else{
				writeLength++;
				
				super.write(c);
			}
		}
		
		public void write(char buf[], int off, int len) {
			if(writeLength==0){
				int start=off;
				
				for(int i=off;i-off0){
					writeLength+=l;
					
					super.write(buf, start, l);
				}
			}else{
				writeLength+=len;
				
				super.write(buf, off, len);
			}			 
		}
		
		public void write(String s, int off, int len) {
			if(len>0){
				writeLength+=len;
				super.write(s, off, len);
			}
		}
		
		 public void println() {
			 if(writeLength>0){
				 super.println();
			 }
		 }
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy