Enable statements log on Postgresql

Open postgresql.conf file and edit:

#log_directory = ‘pg_log’ to log_directory = ‘pg_log’

#log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’ to log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’

#log_statement = ‘none’ to log_statement = ‘all’

#logging_collector = off to logging_collector = on

Optional: SELECT set_config(‘log_statement’, ‘all’, true);

sudo /etc/init.d/postgresql restart or sudo service postgresql restart

Fire query in postgresql select 2+2

Find current log in /var/lib/pgsql/9.2/data/pg_log/

via:
https://stackoverflow.com/a/34664326/3662679

Advertisements

Java JAXRS file download, Rest

@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile(String fileName) {
    File file = ... // Find your file
    return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
        .header("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"")
        .build();
}

via:
https://stackoverflow.com/a/33542797/3662679

PDF file

import java.io.File;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

@Path("/pdf")
public class PdfService {

	private static final String FILE_PATH = "c:\\Android-Book.pdf";

	@GET
	@Path("/get")
	@Produces("application/pdf")
	public Response getFile() {

		File file = new File(FILE_PATH);

		ResponseBuilder response = Response.ok((Object) file);
		response.header("Content-Disposition",
				"attachment; filename=new-android-book.pdf");
		return response.build();

	}

}

via:
https://www.mkyong.com/webservices/jax-rs/download-pdf-file-from-jax-rs/

FTP inputstream & outputstream with Java

Using JDK

URL url = new URL("ftp://user:pass@ftp.something.com/file.txt;type=i");
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream(); // To download
OutputStream os = urlc.getOutputStream(); // To upload

via:
https://stackoverflow.com/questions/12835716/ftpoutputstream-or-similar-in-standard-java

Using Apache Commons

 
https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html