Using Sequence Input Stream in Java

In this post I am going to show you how to use SequenceInputStream in Java. A SequenceInputStream first reads all the bytes from the first stream in the sequence, then all the bytes from the second, third and so on. When the end of one stream is reached, that stream is closed and the next data . . . → Read More: Using Sequence Input Stream in Java

  • Share/Bookmark

Using Data Streams in Java

Data streams read and write strings, integers, floating-point numbers, and other data. The DataInputStream and DataOutputStream classes read and write the primitive Java data types (boolean, int, double, etc.) and strings in a particular, well-defined, platform-independent format. Since DataInputStream and DataOutputStream use the same formats, they’re complementary. These classes are especially useful when you need to move data between platforms that may use different native formats for integers or floating-point numbers.
In this post I am going to show how to use data streams in work. Continue reading Using Data Streams in Java

  • Share/Bookmark

Multitargeting output streams in Java

I want to show how I implemented filter output stream that send data to multiple underlying streams.
It is very easy.
I need output stream for this

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
* New filter stream which helps to write data in 2 streams
* @author The Developer’s Info
*/
public class MultitargetOutputStream extends FilterOutputStream {

private OutputStream . . . → Read More: Multitargeting output streams in Java

  • Share/Bookmark

Using PushBackInputStream in Java

The PushbackInputStream class provides a pushback buffer so a program can “unread” bytes. In other words, it can add bytes to the stream and then read them. This class allows to add data to the stream while they’re reading it. The next time data is read from the stream, the unread bytes are reread.
Example:

import java.io.IOException;
import java.io.PushbackInputStream;

/**
. . . → Read More: Using PushBackInputStream in Java

  • Share/Bookmark

Using buffered streams in Java

Buffered input streams read more data than they initially need into a buffer (an internal array of bytes). When one of the stream’s read() methods is invoked, data is removed from the buffer rather than from the underlying stream. When the buffer runs out of data, the buffered stream refills its buffer from the underlying stream. Also, buffered output streams store data in an internal byte array until the buffer is full or the stream is flushed. Then the data is written out to the underlying output stream in one swoop. In situations where it’s almost as fast to read or write several hundred bytes from the underlying stream as it is to read or write a single byte, a buffered stream can provide a significant performance boost. Continue reading Using buffered streams in Java

  • Share/Bookmark

Using Filter Streams in Java

Filter input streams read data from a preexisting input stream such as a FileInputStream and have an opportunity to work with or change the data before it is delivered to the client program. Filter output streams write data to a preexisting output stream such as a FileOutputStream and have an opportunity to work with or change the data before it is written onto the underlying stream. A stream filter sits between the source of the data and its eventual destination and applies a specific algorithm to the data.
Need to understand that filter streams in Java are very powerful. For example encryption, compression, translation, buffering, and much more. Continue reading Using Filter Streams in Java

  • Share/Bookmark

Using URLConnection in Java

URLConnections are closely related to URLs. Indeed, you get a reference to a URLConnection by using the openConnection() method of an URL object. In many ways, the URL class is only a wrapper around the URLConnection class. URLConnections provide more control over the communication between the client and the server. In particular, URLConnections provide not just input streams by which the client can read data from the server, but also output streams to send data from the client to the server. Continue reading Using URLConnection in Java

  • Share/Bookmark

Using URL in Java

Here I am going to show example which works with URL.
Each URL(Uniform Resource Locator) unambiguously identifies the location of a resource on the Internet.
Example shows how to connect to an URL, download its data and show it in console via System.out

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
* This class shows how to work properly with URL
* . . . → Read More: Using URL in Java

  • Share/Bookmark

Getting separator symbol in Java

This snippet of code allows to get symbol which represents separator in . . . → Read More: Getting separator symbol in Java

  • Share/Bookmark

Writing files in Java

I am going to show example which shows how to write a file in Java.
If you want to write some file you should start with FileOutputStream. This class is a concrete subclass of OutputStream.
Example:

package tutorial;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
* This class shows how to write a file
* @author The Developer’s Info
*/
public class Main . . . → Read More: Writing files in Java

  • Share/Bookmark