Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

FileInputStream - Replace Characters - FileInputStream

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following situation:

I am reading an XML file using FileInputStream and contents are sent to an unmarshaller method that accepts only FileInputStream. We have recently encountereda problem whereby the ampersnad character is not accpetable to the marshaller. My idea was to create a method that reads the file, replaces the ampersand character and writes back the contents to FileInputStream which is used by the unmarsahller.

The issue is that I have not found the way to write to FileInput Stream. The following is the code I am using for testing purposes:


static FileInputStream readInput()
{

StringBuffer buffer = new StringBuffer();
try
{
FileInputStream fis = new FileInputStream("E:\\XYZ.XML");
InputStreamReader isr = new InputStreamReader(fis,"UTF8");

Reader in = new BufferedReader(isr);

int ch;

while ((ch = in.read()) > -1)
{
//buffer.append((char)ch);
String test = (Character.toString((char)ch));
if (test.equals("&"))
{
System.out.println(test);
test = ".&";
}
buffer.append(test);
}
in.close();

return buffer.toString();


}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, it's not possible to write to an InputStream. This demonstrates the advantages of not using specific classes -like FileInputStream- in public interfaces. If the API was using the InputStream interface instead, it would be easy to filter the stream.
 
reply
    Bookmark Topic Watch Topic
  • New Topic