Home > Guides > Core Developers Guide > Result Types > Stream Result
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20

If you are running your app server under HTTPS and having issues with PDF's or other file streams you should take a look at HTTPS and IE Issues

Parameters

Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20

Examples

Annotation based Configuration

To configure Actions and Results with Annotations you need to activate the Struts2 Convention Plugin in your Struts2 application.

package com.mycompany.webapp.actions;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

@Result(
	name = "success", 
	type = "stream", 
	params = { 
		"contentType", "${type}", 
		"inputName", "stream", 
		"bufferSize", "1024", 
		"contentDisposition", "attachment;filename=\"${filename}\"" 
	}
)
public class FileDisplay extends ActionSupport {

	private String type = "image/jpeg";
	private String filename;
	private InputStream stream;

	public String execute() throws Exception {

		filename = "myimage.jpg";
		File img = new File("/path/to/image/image.jpg");
		stream = new FileInputStream(img);

		return Action.SUCCESS;
	}
	
	private String getType() {
		return this.type;
	}
	
	private String getFilename() {
		return this.filename;
	}
	
	private String getStream() {
		return this.stream;
	}
}

XML based Configuration

Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20