1 16 17 18 package org.springframework.beans.propertyeditors; 19 20 import java.beans.PropertyEditorSupport ; 21 import java.io.IOException ; 22 23 import org.springframework.core.io.Resource; 24 import org.springframework.core.io.ResourceEditor; 25 import org.springframework.util.Assert; 26 27 45 public class InputStreamEditor extends PropertyEditorSupport { 46 47 private final ResourceEditor resourceEditor; 48 49 50 54 public InputStreamEditor() { 55 this.resourceEditor = new ResourceEditor(); 56 } 57 58 63 public InputStreamEditor(ResourceEditor resourceEditor) { 64 Assert.notNull(resourceEditor, "ResourceEditor must not be null"); 65 this.resourceEditor = resourceEditor; 66 } 67 68 69 public void setAsText(String text) throws IllegalArgumentException { 70 this.resourceEditor.setAsText(text); 71 Resource resource = (Resource) this.resourceEditor.getValue(); 72 try { 73 setValue(resource != null ? resource.getInputStream() : null); 74 } 75 catch (IOException ex) { 76 throw new IllegalArgumentException ( 77 "Could not retrieve InputStream for " + resource + ": " + ex.getMessage()); 78 } 79 } 80 81 85 public String getAsText() { 86 return null; 87 } 88 89 } 90 | Popular Tags |