Lines 38-43
Link Here
|
38 |
public abstract class JavaElement extends PlatformObject implements IJavaElement { |
38 |
public abstract class JavaElement extends PlatformObject implements IJavaElement { |
39 |
// private static final QualifiedName PROJECT_JAVADOC= new QualifiedName(JavaCore.PLUGIN_ID, "project_javadoc_location"); //$NON-NLS-1$ |
39 |
// private static final QualifiedName PROJECT_JAVADOC= new QualifiedName(JavaCore.PLUGIN_ID, "project_javadoc_location"); //$NON-NLS-1$ |
40 |
|
40 |
|
|
|
41 |
private static final byte[] CLOSING_DOUBLE_QUOTE = new byte[] { 34 }; |
42 |
private static final byte[] CHARSET = new byte[] {99, 104, 97, 114, 115, 101, 116, 61 }; |
43 |
private static final byte[] CONTENT_TYPE = new byte[] { 34, 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 34 }; |
44 |
private static final byte[] CONTENT = new byte[] { 99, 111, 110, 116, 101, 110, 116, 61, 34 }; |
41 |
public static final char JEM_ESCAPE = '\\'; |
45 |
public static final char JEM_ESCAPE = '\\'; |
42 |
public static final char JEM_JAVAPROJECT = '='; |
46 |
public static final char JEM_JAVAPROJECT = '='; |
43 |
public static final char JEM_PACKAGEFRAGMENTROOT = '/'; |
47 |
public static final char JEM_PACKAGEFRAGMENTROOT = '/'; |
Lines 684-728
Link Here
|
684 |
} |
688 |
} |
685 |
|
689 |
|
686 |
/* |
690 |
/* |
687 |
* @see IJavaElement#getAttachedJavadoc(IProgressMonitor, String) |
691 |
* @see IJavaElement#getAttachedJavadoc(IProgressMonitor) |
688 |
*/ |
692 |
*/ |
689 |
public String getAttachedJavadoc(IProgressMonitor monitor, String defaultEncoding) throws JavaModelException { |
693 |
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException { |
690 |
return null; |
694 |
return null; |
691 |
} |
695 |
} |
|
|
696 |
public String getAttachedJavadoc(IProgressMonitor monitor, String encoding) throws JavaModelException { |
697 |
return getAttachedJavadoc(monitor); |
698 |
} |
699 |
|
700 |
int getIndexOf(byte[] array, byte[] toBeFound, int start) { |
701 |
if (array == null || toBeFound == null) |
702 |
return -1; |
703 |
final int toBeFoundLength = toBeFound.length; |
704 |
final int arrayLength = array.length; |
705 |
if (arrayLength < toBeFoundLength) |
706 |
return -1; |
707 |
loop: for (int i = start, max = arrayLength - toBeFoundLength + 1; i < max; i++) { |
708 |
if (array[i] == toBeFound[0]) { |
709 |
for (int j = 1; j < toBeFoundLength; j++) { |
710 |
if (array[i + j] != toBeFound[j]) |
711 |
continue loop; |
712 |
} |
713 |
return i; |
714 |
} |
715 |
} |
716 |
return -1; |
717 |
} |
692 |
/* |
718 |
/* |
693 |
* We don't use getContentEncoding() on the URL connection, because it might leave open streams behind. |
719 |
* We don't use getContentEncoding() on the URL connection, because it might leave open streams behind. |
694 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=117890 |
720 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=117890 |
695 |
* |
721 |
* |
696 |
*/ |
722 |
*/ |
697 |
protected String getURLContents(String docUrlValue, String defaultEncoding) throws JavaModelException { |
723 |
protected String getURLContents(String docUrlValue) throws JavaModelException { |
698 |
InputStream stream = null; |
724 |
InputStream stream = null; |
699 |
try { |
725 |
try { |
700 |
String encoding = defaultEncoding; |
|
|
701 |
try { |
702 |
if (encoding == null) { |
703 |
encoding = this.getJavaProject().getProject().getDefaultCharset(); |
704 |
} |
705 |
} catch (CoreException e) { |
706 |
// ignore |
707 |
} |
708 |
// long time = System.currentTimeMillis(); |
709 |
URL docUrl = new URL(docUrlValue); |
726 |
URL docUrl = new URL(docUrlValue); |
710 |
URLConnection connection = docUrl.openConnection(); |
727 |
URLConnection connection = docUrl.openConnection(); |
711 |
// System.out.println("Time spent " + (System.currentTimeMillis() - time) + "ms for opening connection for " + docUrlValue); //$NON-NLS-1$//$NON-NLS-2$ |
|
|
712 |
// time = System.currentTimeMillis(); |
713 |
if ("jar".equals(docUrl.getProtocol())) { //$NON-NLS-1$ |
728 |
if ("jar".equals(docUrl.getProtocol())) { //$NON-NLS-1$ |
714 |
// if jar protocol is using a cache, some file descriptors are left behind and the resource cannot be deleted |
729 |
// if jar protocol is using a cache, some file descriptors are left behind and the resource cannot be deleted |
715 |
connection.setUseCaches(false); |
730 |
connection.setUseCaches(false); |
716 |
} |
731 |
} |
|
|
732 |
String encoding = connection.getContentEncoding(); |
717 |
stream = new BufferedInputStream(connection.getInputStream()); |
733 |
stream = new BufferedInputStream(connection.getInputStream()); |
718 |
// System.out.println("Time spent " + (System.currentTimeMillis() - time) + "ms for getting stream for " + docUrlValue); //$NON-NLS-1$//$NON-NLS-2$ |
734 |
byte[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(stream, connection.getContentLength()); |
719 |
// time = System.currentTimeMillis(); |
735 |
if (encoding == null) { |
720 |
char[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, -1, encoding); |
736 |
int index = getIndexOf(contents, CONTENT_TYPE, 0); |
721 |
// System.out.println("Time spent " + (System.currentTimeMillis() - time) + "ms for reading stream for " + docUrlValue); //$NON-NLS-1$//$NON-NLS-2$ |
737 |
if (index != -1) { |
722 |
if (contents != null) { |
738 |
index = getIndexOf(contents, CONTENT, index); |
723 |
// System.out.println("Size = " + (contents.length / 1024) + "kb");//$NON-NLS-1$//$NON-NLS-2$ |
739 |
if (index != -1) { |
724 |
return String.valueOf(contents); |
740 |
int offset = index + CONTENT.length; |
|
|
741 |
int index2 = getIndexOf(contents, CLOSING_DOUBLE_QUOTE, offset); |
742 |
if (index2 != -1) { |
743 |
final int charsetIndex = getIndexOf(contents, CHARSET, offset); |
744 |
if (charsetIndex != -1) { |
745 |
int start = charsetIndex + CHARSET.length; |
746 |
encoding = new String(contents, start, index2 - start, "UTF-8"); //$NON-NLS-1$ |
747 |
} |
748 |
} |
749 |
} |
750 |
} |
751 |
} |
752 |
try { |
753 |
if (encoding == null) { |
754 |
encoding = this.getJavaProject().getProject().getDefaultCharset(); |
755 |
} |
756 |
} catch (CoreException e) { |
757 |
// ignore |
725 |
} |
758 |
} |
|
|
759 |
if (contents != null) { |
760 |
if (encoding != null) { |
761 |
return new String(contents, encoding); |
762 |
} else { |
763 |
// platform encoding is used |
764 |
return new String(contents); |
765 |
} |
766 |
} |
726 |
} catch (MalformedURLException e) { |
767 |
} catch (MalformedURLException e) { |
727 |
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); |
768 |
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, this)); |
728 |
} catch (FileNotFoundException e) { |
769 |
} catch (FileNotFoundException e) { |