Skip to content

Instantly share code, notes, and snippets.

@csokol
Created March 4, 2013 22:42
Show Gist options
  • Save csokol/5086351 to your computer and use it in GitHub Desktop.
Save csokol/5086351 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.resource.ResourceMethod;
@Component
public class ArquivosParaDeletar {
private List<File> arquivos = new ArrayList<>();
private boolean podeDeletar = false;
public void adiciona(File f) {
arquivos.add(f);
}
public void podeDeletar() {
podeDeletar = true;
}
public void deleta() {
if (podeDeletar) {
for (File f : arquivos) {
f.delete();
}
}
}
}
class Controller {
private ArquivosParaDeletar arquivosParaDeletar;
public Controller(ArquivosParaDeletar arquivos) {
this.arquivosParaDeletar = arquivos;
}
public void deleta() {
arquivosParaDeletar.adiciona(new File("/tmp/qualquer.txt"));
}
}
class MeuInterceptor implements Interceptor {
private ArquivosParaDeletar arquivosParaDeletar;
public MeuInterceptor(ArquivosParaDeletar arquivos) {
this.arquivosParaDeletar = arquivos;
}
@Override
public boolean accepts(ResourceMethod arg0) {
return true;
}
@Override
public void intercept(InterceptorStack s, ResourceMethod m, Object o)
throws InterceptionException {
s.next(m, o);
arquivosParaDeletar.deleta();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment