Java Examples for com.google.dart.engine.utilities.translation.DartOmit

The following java examples will help you to understand the usage of com.google.dart.engine.utilities.translation.DartOmit. These source code samples are taken from different open source projects.

Example 1
Project: eclipse3-master  File: FileBasedSource.java View source code
/**
   * Get the contents of underlying file and pass it to the given receiver.
   * 
   * @param receiver the content receiver to which the content of this source will be passed
   * @throws Exception if the contents of this source could not be accessed
   * @see #getContentsToReceiver(ContentReceiver)
   */
@DartOmit
protected void getContentsFromFileToReceiver(ContentReceiver receiver) throws Exception {
    long modificationTime = file.lastModified();
    try {
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
        FileChannel channel = null;
        ByteBuffer byteBuffer = null;
        try {
            channel = randomAccessFile.getChannel();
            long size = channel.size();
            if (size > Integer.MAX_VALUE) {
                throw new IllegalStateException("File is too long to be read");
            }
            int length = (int) size;
            byte[] bytes = new byte[length];
            byteBuffer = ByteBuffer.wrap(bytes);
            byteBuffer.position(0);
            byteBuffer.limit(length);
            channel.read(byteBuffer);
        } catch (ClosedByInterruptException exception) {
            byteBuffer = null;
        } finally {
            try {
                randomAccessFile.close();
            } catch (IOException closeException) {
            }
        }
        if (byteBuffer != null) {
            byteBuffer.rewind();
            skipOptionalBOM(byteBuffer);
            receiver.accept(UTF_8_CHARSET.decode(byteBuffer), modificationTime);
            return;
        }
    } catch (IOException exception) {
    }
    //
    // Eclipse appears to be interrupting the thread sometimes. If we couldn't read the file using
    // the native I/O support, try using the non-native support.
    //
    InputStreamReader reader = null;
    String contents;
    try {
        reader = new InputStreamReader(getFileInputStreamWithoutBOM(), "UTF-8");
        contents = FileUtilities.getContents(reader);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException closeException) {
            }
        }
    }
    receiver.accept(contents, modificationTime);
}