Posts

Showing posts from 2022

PostgreSQL: setup User and Role in Linux (Mint)

After installing PostgreSQL, type the following command: $ psql -U postgres postgres is the default super user. We login as Postgresql database system by using this super user.  Display existing user's roles: postgres-# \du+  Create ps_admin role: postgres=# CREATE ROLE ps_admin WITH LOGIN CREATEDB PASSWORD 'admin'; The ps_admin can login with password 'admin' and can create new database. Note: Here, password is simply 'admin'. In the real life the password should be complex combination of words, symbols and numbers. Display list of roles: postgres=# \du+ You will see something like below: Role Name: ps_admin List of roles Attributes: Create DB Create Database: $createdb testdb -p 5432 -h localhost -U ps_admin; The createdb is command line command. The database name testdb will be created under ps_admin user. It should be run in the console. -p = port (default port is 5432) -h = hostname (default hostname is loclhost) -U = username (ps_admin) It will be prom

How to Convert OutputStream to InputStream

Sometime we need to convert Output Stream to Input Stream. We can perform the conversion multiple ways.  The following two approaches are most popular: 1. ByteArrayOutputStream to ByteArrayInputStream 2. PipedOutputStream to PipedInputStream Complete example code is available in the [ Github ]. Approach 1: ByteArrayOutputStream/ByteArrayInputStream The ByteArrayOutputStream/ByteArrayInputStream is the easiest way to convert OutputStream to InputStream. Code snippet: TextWriter textWriterBins = new TextWriter(); ByteArrayOutputStream bouts = new ByteArrayOutputStream(); textWriterBins.write(bouts); ByteArrayInputStream bins = new ByteArrayInputStream(bouts.toByteArray()); TextReader textReader = new TextReader(bins); textReader.print(); Here, TextWriter is a class which writes some text in the OutputStream and TextReader is a class which reads data from InputStream and print on the console. In the above code snippet, the TextWriter.write method writes the data in the