use of org.eclipse.wst.sse.core.internal.encoding.CodedStreamCreator in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method saveStructuredDocument.
public void saveStructuredDocument(IStructuredDocument structuredDocument, IFile iFile, EncodingRule encodingRule) throws UnsupportedEncodingException, CoreException, IOException {
// $NON-NLS-1$
Assert.isNotNull(iFile, "file parameter can not be null");
if (FileBufferModelManager.getInstance().isExistingBuffer(structuredDocument)) {
ITextFileBuffer buffer = FileBufferModelManager.getInstance().getBuffer(structuredDocument);
if (iFile.getFullPath().equals(buffer.getLocation()) || (iFile.getLocation() != null && iFile.getLocation().equals(buffer.getLocation())) || (iFile.getLocationURI() != null && buffer.getFileStore() != null && iFile.getLocationURI().equals(buffer.getFileStore().toURI()))) {
buffer.commit(new NullProgressMonitor(), true);
}
} else {
// IModelHandler handler = calculateType(iFile);
// IDocumentDumper dumper = handler.getDocumentDumper();
CodedStreamCreator codedStreamCreator = new CodedStreamCreator();
Reader reader = new DocumentReader(structuredDocument);
codedStreamCreator.set(iFile, reader);
codedStreamCreator.setPreviousEncodingMemento(structuredDocument.getEncodingMemento());
EncodingMemento encodingMemento = codedStreamCreator.getCurrentEncodingMemento();
// be sure document's is updated, in case exception is thrown in
// getCodedByteArrayOutputStream
structuredDocument.setEncodingMemento(encodingMemento);
// Convert line delimiters after encoding memento is figured out,
// but
// before writing to output stream.
handleConvertLineDelimiters(structuredDocument, iFile, encodingRule, encodingMemento);
ByteArrayOutputStream codedByteStream = codedStreamCreator.getCodedByteArrayOutputStream(encodingRule);
InputStream codedStream = new ByteArrayInputStream(codedByteStream.toByteArray());
if (iFile.exists())
iFile.setContents(codedStream, true, true, null);
else
iFile.create(codedStream, false, null);
codedByteStream.close();
codedStream.close();
}
}
Aggregations