Search in sources :

Example 6 with CodedReaderCreator

use of org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator in project webtools.sourceediting by eclipse.

the class CreateCodedReaderTester method testCreateAllFiles.

public void testCreateAllFiles() throws CoreException, IOException {
    if (RECREATE_FILES) {
        List allFiles = TestsPlugin.getAllTestFiles(TEST_FILE_DIR);
        URL outputDirURL = TestsPlugin.getInstallLocation();
        File zipoutFile = new File(outputDirURL.getPath(), TESTFILES_ZIPFILE_NAME);
        java.io.FileOutputStream zipOut = new FileOutputStream(zipoutFile);
        ZipOutputStream zipOutputStream = new ZipOutputStream(zipOut);
        int count = 1;
        for (Iterator iter = allFiles.iterator(); iter.hasNext(); ) {
            File file = (File) iter.next();
            createZipEntry(zipOutputStream, file);
            CodedReaderCreator codedReaderCreator = new CodedReaderCreator();
            codedReaderCreator.set(file.getName(), new FileInputStream(file));
            String detectedCharsetName = null;
            String javaCharsetName = null;
            String expectedException = null;
            try {
                // just used for debug info, but can throw exception
                javaCharsetName = codedReaderCreator.getEncodingMemento().getJavaCharsetName();
                detectedCharsetName = codedReaderCreator.getEncodingMemento().getDetectedCharsetName();
            } catch (UnsupportedCharsetExceptionWithDetail e) {
                // ignore for simply creating tests
                expectedException = e.getClass().getName() + ".class";
            } catch (MalformedInputException e) {
                // ignore for simply creating tests
                expectedException = e.getClass().getName() + ".class";
            } catch (IllegalCharsetNameException e) {
                // ignore for simply creating tests
                expectedException = e.getClass().getName() + ".class";
            }
            String subpath = getSubPathName(file);
            createTestMethodSource(count, subpath, detectedCharsetName, javaCharsetName, expectedException);
            count++;
        }
        zipOutputStream.close();
        zipOut.close();
        assertTrue(true);
    }
}
Also used : CodedReaderCreator(org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator) FileOutputStream(java.io.FileOutputStream) URL(java.net.URL) FileInputStream(java.io.FileInputStream) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) MalformedInputException(java.nio.charset.MalformedInputException) List(java.util.List) UnsupportedCharsetExceptionWithDetail(org.eclipse.wst.sse.core.internal.exceptions.UnsupportedCharsetExceptionWithDetail) File(java.io.File)

Aggregations

CodedReaderCreator (org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator)6 CoreException (org.eclipse.core.runtime.CoreException)3 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)3 Reader (java.io.Reader)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 MalformedInputException (java.nio.charset.MalformedInputException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)1 IDocument (org.eclipse.jface.text.IDocument)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)1 UnsupportedCharsetExceptionWithDetail (org.eclipse.wst.sse.core.internal.exceptions.UnsupportedCharsetExceptionWithDetail)1