1 5 package com.oreilly.servlet.multipart; 6 7 import java.io.ByteArrayOutputStream ; 8 import java.io.IOException ; 9 import java.io.UnsupportedEncodingException ; 10 import javax.servlet.ServletInputStream ; 11 12 23 public class ParamPart extends Part { 24 25 26 private byte[] value; 27 28 private String encoding; 29 30 39 ParamPart(String name, ServletInputStream in, 40 String boundary, String encoding) throws IOException { 41 super(name); 42 this.encoding = encoding; 43 44 PartInputStream pis = new PartInputStream(in, boundary); 46 ByteArrayOutputStream baos = new ByteArrayOutputStream (512); 47 byte[] buf = new byte[128]; 48 int read; 49 while ((read = pis.read(buf)) != -1) { 50 baos.write(buf, 0, read); 51 } 52 pis.close(); 53 baos.close(); 54 55 value = baos.toByteArray(); 57 } 58 59 65 public byte[] getValue() { 66 return value; 67 } 68 69 76 public String getStringValue() 77 throws UnsupportedEncodingException { 78 return getStringValue(encoding); 79 } 80 81 87 public String getStringValue(String encoding) 88 throws UnsupportedEncodingException { 89 return new String (value, encoding); 90 } 91 92 97 public boolean isParam() { 98 return true; 99 } 100 } 101 | Popular Tags |