com.sun.codemodel.internal.util.EncoderFactory Java Examples

The following examples show how to use com.sun.codemodel.internal.util.EncoderFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #2
Source File: CodeWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #3
Source File: CodeWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #4
Source File: CodeWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #5
Source File: CodeWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #6
Source File: CodeWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #7
Source File: CodeWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}
 
Example #8
Source File: CodeWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by CodeModel to store the specified file.
 * The callee must allocate a storage to store the specified file.
 *
 * <p>
 * The returned stream will be closed before the next file is
 * stored. So the callee can assume that only one OutputStream
 * is active at any given time.
 *
 * @param   pkg
 *      The package of the file to be written.
 * @param   fileName
 *      File name without the path. Something like
 *      "Foo.java" or "Bar.properties"
 */
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
    final OutputStreamWriter bw = encoding != null
            ? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
            : new OutputStreamWriter(openBinary(pkg,fileName));

    // create writer
    try {
        return new UnicodeEscapeWriter(bw) {
            // can't change this signature to Encoder because
            // we can't have Encoder in method signature
            private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
            @Override
            protected boolean requireEscaping(int ch) {
                // control characters
                if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 )  return true;
                // check ASCII chars, for better performance
                if( ch<0x80 )       return false;

                return !encoder.canEncode((char)ch);
            }
        };
    } catch( Throwable t ) {
        return new UnicodeEscapeWriter(bw);
    }
}