Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » java.util.Properties in to a IFile??
java.util.Properties in to a IFile?? [message #247498] Mon, 31 May 2004 10:49 Go to next message
Eclipse User
Originally posted by: purjo76.luukku.com

Hi!

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??
Re: java.util.Properties in to a IFile?? [message #247512 is a reply to message #247498] Mon, 31 May 2004 11:14 Go to previous message
Andreas Herz is currently offline Andreas Herz
Messages: 196
Registered: July 2009
Senior Member
Hi,

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());

((IFileEditorInput)getEditorInput()).getFile().setContents(i nputStream,true,false,monitor);

// 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();
}
}
Previous Topic:Illegal Thread Access
Next Topic:Form&Source Editor
Goto Forum:
  


Current Time: Sat Sep 20 04:09:55 GMT 2014

Powered by FUDForum. Page generated in 0.01561 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software