On Oct 19, 11:35 am, "Firmansyah ." <[email protected]> wrote: > IMO: > for the text file maybe it is the same , i means no uppercase, because it is > filter so i just uppercase when read and write process and the result of the > uppercase displayed into console, so i just modify Adler32 class like this: > public class Adler32 implements Checksum { > > private int value = 1; > private StringBuffer uppercase=new StringBuffer(""); > > /* > * BASE is the largest prime number smaller than 65536 > * NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 > */ > private static final int BASE = 65521; > private static final int NMAX = 5552; > private static final int cMin = Character.MIN_VALUE; > private static final int cMax = Character.MAX_VALUE; > > /** > * Update current Adler-32 checksum given the specified byte. > */ > public void update(int b) { > int s1 = value & 0xffff; > int s2 = (value >> 16) & 0xffff; > s1 += b & 0xff; > s2 += s1; > value = ((s2 % BASE) << 16) | (s1 % BASE); > if (b >= cMin || b <= cMax) { > uppercase.append(Character.toUpperCase((char) b)); > } > } > > /** > * Update current Adler-32 checksum given the specified byte array. > */ > public void update(byte[] b, int off, int len) { > int s1 = value & 0xffff; > int s2 = (value >> 16) & 0xffff; > > while (len > 0) { > int k = len < NMAX ? len : NMAX; > len -= k; > while (k-- > 0) { > s1 += b[off++] & 0xff; > s2 += s1; > } > s1 %= BASE; > s2 %= BASE; > } > value = (s2 << 16) | s1; > while(len > 0) > { > int k = len < cMax ? len : cMax; > len -= k; > while (k-- > 0) { > uppercase.append(Character.toUpperCase((char) b[off++])); > } > > } > } > > /** > * Reset Adler-32 checksum to initial value. > */ > public void reset() { > value = 1; > } > > /** > * Returns current checksum value. > */ > public long getValue() { > return (long) value & 0xffffffff; > } > > /** > * @return the uppercase > */ > public String getUppercase() { > return uppercase.toString(); > } > > } I have read the original Addler32 class repeatedly. However, I am still clueless. Someone got any idea what this class does. Thank you. > > ________________________________ > From: DaveB <[email protected]> > To: Free Java Programming Online Training Course By Sang Shin > <[email protected]> > Sent: Mon, October 19, 2009 6:44:55 AM > Subject: [java programming] Re: lab-1022:Java Stream I/O > > All: > I am also having difficulty understanding what we are trying to > achieve. I do not understand why we need two more classes. If the > goal is to create the output file all in upper case, then why would we > not just check the int from the read and subtract 32 like this: > > int c; > while ((c = in.read()) != -1) > out.write((c > 96 && c < 123)? (c-32):c); > > It produces the outagain.txt file: > > SO SHE WENT INTO THE GARDEN TO CUT A CABBAGE-LEAF, TO > MAKE AN APPLE-PIE; AND AT THE SAME TIME A GREAT > SHE-BEAR, COMING UP THE STREET, POPS ITS HEAD INTO THE > SHOP. 'WHAT! NO SOAP?' SO HE DIED, AND SHE VERY > IMPRUDENTLY MARRIED THE BARBER; AND THERE WERE > PRESENT THE PICNINNIES, AND THE JOBLILLIES, AND THE > GARYALIES, AND THE GRAND PANJANDRUM HIMSELF, WITH THE > LITTLE ROUND BUTTON AT TOP, AND THEY ALL FELL TO PLAYING > THE GAME OF CATCH AS CATCH CAN, TILL THE GUN POWDER RAN > OUT AT THE HEELS OF THEIR BOOTS. > > SAMUEL FOOTE 1720-1777 > > What am I missing? > > DaveB > > On Oct 17, 6:59 pm, "Firmansyah ." <[email protected]> wrote: > > > > > can anyone explain more briefly the homework in lab 1022 which said that > > "Use either ChangeToUpperCaseInputStream class or > > ChangeToUpperCaseOutputStream class to convert the characters read to > > upper case"? > > > is it using character stream to make so correctly read char, and then the > > return of method read() converted to char. > > after this we call Character.toUpperCase(ch) method?
--~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
