DigestInputStream.toString() method in Java with Examples Last Updated : 05 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The toString() method of java.security.DigestInputStream class provide the object of DigestInputStream in string format.Syntax: public String toString() Return Value: This method returns the object of DigestInputStream in string format.Note : All the programs in this article won’t run on online IDE as no ‘name’ file exists. You can check this code on Java compiler on your system. To check this code, create a file ‘name’ on your system.Below are the examples to illustrate the toString() method:Example 1: Java // Java program to demonstrate // toString() method import java.security.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // creating the object of MessageDigest // and getting instance // By using getInstance() method MessageDigest sr = MessageDigest.getInstance("MD5"); // creating and initializing // object of InputStream InputStream is = new FileInputStream("f:/java/name.txt"); // creating and initializing // object of DigestInputStream DigestInputStream di = new DigestInputStream(is, sr); // getting the string representation // of DigestInputStream // using toString() method String str = di.toString(); // display the result System.out.println("Status : " + str); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } catch (FileNotFoundException e) { System.out.println("Exception thrown : " + e); } } } Output: Status : [Digest Input Stream] MD5 Message Digest from SUN, Example 2: Java // Java program to demonstrate // toString() method import java.security.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // creating the object of MessageDigest // and getting instance // By using getInstance() method MessageDigest sr = MessageDigest.getInstance("SHA-1"); // creating and initializing // object of InputStream InputStream is = new FileInputStream("f:/java/name.txt"); // creating and initializing // object of DigestInputStream DigestInputStream di = new DigestInputStream(is, sr); // getting the string // representation of DigestInputStream // using toString() method String str = di.toString(); // display the result System.out.println("Status : " + str); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } catch (FileNotFoundException e) { System.out.println("Exception thrown : " + e); } } } Output: Status : [Digest Input Stream] SHA-1 Message Digest from SUN, Reference: https://docs.oracle.com/javase/9/docs/api/java/security/DigestInputStream.html#toString-- Comment More infoAdvertise with us Next Article DataInputStream readLong() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-security package Java-DigestInputStream Practice Tags : Java Similar Reads DigestOutputStream.toString() method in Java with Examples The toString() method of java.security.DigestOutputStream class used to provide the object of DigestOutputStream in string format. Syntax: public String toString() Return Value: This method returns the object of DigestOutputStream in string format. Note: All the programs in this article wonât run on 2 min read DataInputStream readInt() method in Java with Examples The readInt() method of DataInputStream class in Java is used to read four input bytes and returns a integer value. This method reads the next four bytes from the input stream and interprets it into integer type and returns. Syntax: public final int readInt() throws IOException Specified By: This me 2 min read DigestInputStream.setMessageDigest() method in Java with Examples The setMessageDigest() method of java.security.DigestInputStream class used to assign the specified MessageDigest to DigestInputStream object. Syntax: public void setMessageDigest(MessageDigest digest) Return Value: This method has nothing to return. Note: All the programs in this article wonât run 3 min read DataInputStream read() method in Java with Examples The read() method of DataInputStream class in Java is of two types: read(byte[] b) method of DataInputStream class in Java is used to read bytes from the input stream and store them into the buffer byte array.This read() method returns the number of bytes actually read as an integer type. This metho 4 min read DataInputStream readLong() method in Java with Examples The readLong() method of DataInputStream class in Java is used to read eight input bytes and returns a long value. This method reads the next eight bytes from the input stream and interprets it into long type and returns. Syntax: public final long readLong() throws IOException Specified By: This met 2 min read DataInputStream readShort() method in Java with Examples The readShort() method of DataInputStream class in Java is used to read two input bytes and returns a short value. This method reads the next two bytes from the input stream and interprets it into short type and returns. Syntax: public final short readShort() throws IOException Specified By: This me 2 min read Like