use of org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method saveModel.
/**
* @deprecated - this method is less efficient than IFile form, since it
* requires an extra "copy" of byte array, and should be avoid
* in favor of the IFile form.
*/
public void saveModel(String id, OutputStream outputStream, EncodingRule encodingRule) throws UnsupportedEncodingException, CoreException, IOException {
// $NON-NLS-1$
Assert.isNotNull(id, "id parameter can not be null");
SYNC.acquire();
// let's see if we already have it in our cache
SharedObject sharedObject = (SharedObject) fManagedObjects.get(id);
if (sharedObject == null) {
SYNC.release();
// $NON-NLS-1$ = "Program Error: ModelManagerImpl::saveModel. Model should be in the cache"
throw new IllegalStateException(SSECoreMessages.Program_Error__ModelManage_EXC_);
} else {
SYNC.release();
sharedObject.waitForLoadAttempt();
synchronized (sharedObject) {
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
codedStreamCreator.set(sharedObject.theSharedModel.getId(), new DocumentReader(sharedObject.theSharedModel.getStructuredDocument()));
codedStreamCreator.setPreviousEncodingMemento(sharedObject.theSharedModel.getStructuredDocument().getEncodingMemento());
ByteArrayOutputStream byteArrayOutputStream = codedStreamCreator.getCodedByteArrayOutputStream(encodingRule);
byte[] outputBytes = byteArrayOutputStream.toByteArray();
outputStream.write(outputBytes);
// $NON-NLS-1$
trace("saving model", id);
sharedObject.theSharedModel.setDirtyState(false);
sharedObject.theSharedModel.setNewState(false);
}
}
}
use of org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator in project webtools.sourceediting by eclipse.
the class TestCodedWrite method testSimplest.
public void testSimplest() throws UnsupportedEncodingException, CoreException, IOException {
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
String text = "test text";
codedStreamCreator.set("dummy.xml", text);
ByteArrayOutputStream outputStream = codedStreamCreator.getCodedByteArrayOutputStream(EncodingRule.CONTENT_BASED);
if (DEBUG) {
debugPrint("testSimplest", text, null, outputStream);
}
assertNotNull(outputStream);
}
use of org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator in project webtools.sourceediting by eclipse.
the class TestCodedWrite method testSimple.
public void testSimple() throws UnsupportedEncodingException, CoreException, IOException {
String jsp = "<%@ page contentType=\"text/html; charset=ISO-8859-3\"%>";
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
codedStreamCreator.set("dummy.jsp", jsp);
ByteArrayOutputStream outputStream = codedStreamCreator.getCodedByteArrayOutputStream(EncodingRule.CONTENT_BASED);
if (DEBUG) {
debugPrint("testSimple", jsp, "ISO-8859-3", outputStream);
}
assertNotNull(outputStream);
}
use of org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator in project webtools.sourceediting by eclipse.
the class TestCodedWrite method testSimpleUTF16BE.
public void testSimpleUTF16BE() throws UnsupportedEncodingException, CoreException, IOException {
String jsp = "<%@ page contentType=\"text/html; charset=UTF-16BE\"%>";
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
codedStreamCreator.set("dummy.jsp", jsp);
ByteArrayOutputStream outputStream = codedStreamCreator.getCodedByteArrayOutputStream(EncodingRule.CONTENT_BASED);
if (DEBUG) {
debugPrint("testSimpleUTF16BE", jsp, "UTF-16BE", outputStream);
}
assertNotNull(outputStream);
}
use of org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator in project webtools.sourceediting by eclipse.
the class TestCodedWrite method testSimpler.
public void testSimpler() throws UnsupportedEncodingException, CoreException, IOException {
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><tag>test text</tag>";
codedStreamCreator.set("dummy.xml", xmlString);
ByteArrayOutputStream outputStream = codedStreamCreator.getCodedByteArrayOutputStream(EncodingRule.CONTENT_BASED);
if (DEBUG) {
debugPrint("testSimpler", xmlString, "UTF-16", outputStream);
}
assertNotNull(outputStream);
}
Aggregations