Search in sources :

Example 1 with CodedStreamCreator

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);
        }
    }
}
Also used : CodedStreamCreator(org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with CodedStreamCreator

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);
}
Also used : CodedStreamCreator(org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with CodedStreamCreator

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);
}
Also used : CodedStreamCreator(org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with CodedStreamCreator

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);
}
Also used : CodedStreamCreator(org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with CodedStreamCreator

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);
}
Also used : CodedStreamCreator(org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CodedStreamCreator (org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator)6 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 EncodingMemento (org.eclipse.wst.sse.core.internal.encoding.EncodingMemento)1