Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code is for java and I would like to change my read method to read certain characters and stop at white spaces and then

This code is for java and I would like to change my read method to read certain characters and stop at white spaces and then continue to read other bytes of char information.

my method will take in a ppm file and I will turn the file into an BufferedInputStream Object as shown below. I do not want to use BufferedReader from the java library.

The goal of my program is to convert the file to binary bytes then place each bit into a 1 D char array so that I can change image later but I am stuck because I can not get the dimensions of the picture which is in the red circle in the picture because of the whitespace that is between the numeric values.

public void readImage (String ppmFileName)throws FileNotFoundException,IOException { BufferedInputStream input = new BufferedInputStream(new FileInputStream(imageFileName)); char ch1 = (char)input.read(); char ch2 = (char)input.read(); String newMagicNumber = ""+ch1+ch2; this.magicNumber = newMagicNumber; System.out.println(magicNumber);

while(input.read() != ' ') { // ch3 = (char) input.read(); System.out.println((int)ch3); this.width = (int)ch3; }

My while loop needs to change in order to stop at a whitespace then maybe create the another while loop to get the next set of char bytes after the whitespace.

My mediate goal is to get the data that is circle in red in the picture below. The Magic Number and the max color values I can get just not the values from line 2 in the picture.

image text in transcribed

How can I change my while loop to do this task?

Note: That this method should be dynamic because the dimensions of each image is different.

m PG 736 552 255 lu lw z " "1$f0%,,1%, '1'&&*&&*&* ' ' & ' & % "+ ,I} i{ lw lu ir A+I@IA- ? H+JC; 17A61614*11I/ 04125140 7- =ul?9/. O) I$I!"("01* 40CN'R"2R 8L- 28!0$33-15-17-1:"19.182-".

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions