How do i save a content of a Properties class in to a EclipseĊ½s IFile
instance?? In Properties there are store() and load() methods, but how do
set the file where to store to be an IFile??
I think it is not the best way.....but it is a way.
Create a class StringBufferOutputStream like the class which i append in the footer.
Implement the doSave(...) method in your Editor.
/**
* Saves editor's document.
*/
public void doSave(IProgressMonitor monitor)
{
try
{
// your properties to save!!!!
Properties props =new Properties();
// stream the properties into a buffer
//
StringBufferOutputStream out=new StringBufferOutputStream();
props.save(out);
// use the created buffer as inputStream for the IFile.setContents method.
//
StringBufferInputStream inputStream=new StringBufferInputStream(out.toString());
// mark the file as saved
//
getCommandStack().markSaveLocation();
}
catch (Exception e)
{
// TODO: do the error handling...
e.printStackTrace();
}
}
Greetings
Andreas
P.S. A better solutions are welcome ;-)
============================================================ ====================
public class StringBufferOutputStream extends OutputStream implements Serializable
{
protected StringBuffer buf;
public StringBufferOutputStream(StringBuffer sb)
{
buf = sb;
}
public StringBufferOutputStream(int defaultBufferSize)
{
buf = new StringBuffer(defaultBufferSize);
}
public void close()
{
buf = null;
}
public void write(byte abyte0[])
{
buf.append(toCharArray(abyte0));
}
public void write(byte abyte0[], int i, int j)
{
if (i < 0 || j < 0 || i + j > abyte0.length)
throw new IndexOutOfBoundsException("Parameters out of bounds.");
byte abyte1[] = new byte[j];
for (int k = 0; k < j; k++)
{
abyte1[k] = abyte0[i];
i++;
}
buf.append(toCharArray(abyte1));
}
public void write(int i)
{
buf.append((char) i);
}
private static char[] toCharArray(byte abyte0[])
{
if (abyte0 == null)
return null;
char ac[] = new char[abyte0.length];
for (int i = 0; i < abyte0.length; i++)
ac[i] = (char) abyte0[i];
return ac;
}
public String toString()
{
return buf.toString();
}
}