private String fileNameFor(final String packageName, final String sourceName) { String result; SourceFinder sourceFinder = AnalysisContext.currentAnalysisContext().getSourceFinder(); try { result = sourceFinder.findSourceFile(packageName, sourceName).getFullFileName(); } catch (IOException e) { result = packageName.replace('.', File.separatorChar) + File.separatorChar + sourceName; } return result; }
public InputStream openSource(SourceLineAnnotation source) throws IOException { SourceFile sourceFile = findSourceFile(source); return sourceFile.getInputStream(); }
/** * A zip or jar archive containing source files. */ static class ZipSourceRepository implements SourceRepository { ZipFile zipFile; public ZipSourceRepository(@WillCloseWhenClosed ZipFile zipFile) { this.zipFile = zipFile; } @Override public boolean contains(String fileName) { return zipFile.getEntry(fileName) != null; } @Override public boolean isPlatformDependent() { return false; } @Override public SourceFileDataSource getDataSource(String fileName) { return new ZipSourceFileDataSource(zipFile, fileName); } @Override public void close() throws IOException { zipFile.close(); } }
OutputStream out = null; try { long lastModified = sourceFile.getLastModified(); in = sourceFile.getInputStream(); out = getOutputStream(fullName, 0); if (out == null) {
private synchronized void loadFileData() throws IOException { if (data != null) { return; } InputStream in = null; try { in = dataSource.open(); ByteArrayOutputStream out = new ByteArrayOutputStream(); addLineOffset(0); // Line 0 starts at offset 0 LineNumberMapBuilder mapBuilder = new LineNumberMapBuilder(this); // Copy all of the data from the file into the byte array output // stream byte[] buf = new byte[1024]; int n; while ((n = in.read(buf)) >= 0) { mapBuilder.addData(buf, n); out.write(buf, 0, n); } mapBuilder.eof(); setData(out.toByteArray()); } finally { if (in != null) { in.close(); } } }
int offset = sourceFile.getLineOffset(scanStartLine - 1); if (offset < 0) Tokenizer tokenizer = new Tokenizer(UTF8.reader(sourceFile.getInputStreamFromOffset(offset)));
@Nonnull private JavaSourceDocument getDocument(SourceLineAnnotation source) { try { SourceFile sourceFile = frame.getProject().getSourceFinder().findSourceFile(source); String fullFileName = sourceFile.getFullFileName(); SoftReference<JavaSourceDocument> resultReference = map.get(fullFileName); JavaSourceDocument result = null; if (resultReference != null) { result = resultReference.get(); } if (result != null) { return result; } try { InputStream in = sourceFile.getInputStream(); result = new JavaSourceDocument(source.getClassName(), SourceCharset.bufferedReader(in), sourceFile); } catch (Exception e) { result = JavaSourceDocument.UNKNOWNSOURCE; Debug.println(e); // e.printStackTrace(); } map.put(fullFileName, new SoftReference<JavaSourceDocument>(result)); return result; } catch (Exception e) { Debug.println(e); // e.printStackTrace(); return JavaSourceDocument.UNKNOWNSOURCE; } }
/** * Get an InputStream on data starting at given offset. * * @param offset * the start offset * @return an InputStream on the data in the source file, starting at the * given offset */ public InputStream getInputStreamFromOffset(int offset) throws IOException { loadFileData(); return new ByteArrayInputStream(data, offset, data.length - offset); }
private void add(int ch) { switch (ch) { case '\n': sourceFile.addLineOffset(offset + 1); break; case '\r': // Need to see next character to know if it's a // line terminator. break; default: if (lastSeen == '\r') { // We consider a bare CR to be an end of line // if it is not followed by a new line. // Mac OS has historically used a bare CR as // its line terminator. sourceFile.addLineOffset(offset); } } lastSeen = ch; ++offset; } }
long when = sourceFile.getLastModified(); if (when > 0) { Date firstSeen = new Date(when);
OutputStream out = null; try { long lastModified = sourceFile.getLastModified(); in = sourceFile.getInputStream(); out = getOutputStream(fullName, 0); if (out == null) {
private synchronized void loadFileData() throws IOException { if (data != null) { return; } InputStream in = null; try { in = dataSource.open(); ByteArrayOutputStream out = new ByteArrayOutputStream(); addLineOffset(0); // Line 0 starts at offset 0 LineNumberMapBuilder mapBuilder = new LineNumberMapBuilder(this); // Copy all of the data from the file into the byte array output // stream byte[] buf = new byte[1024]; int n; while ((n = in.read(buf)) >= 0) { mapBuilder.addData(buf, n); out.write(buf, 0, n); } mapBuilder.eof(); setData(out.toByteArray()); } finally { if (in != null) { in.close(); } } }
int offset = sourceFile.getLineOffset(scanStartLine - 1); if (offset < 0) Tokenizer tokenizer = new Tokenizer(UTF8.reader(sourceFile.getInputStreamFromOffset(offset)));
/** * Get an InputStream on data. * * @return an InputStream on the data in the source file, starting from * given offset */ public InputStream getInputStream() throws IOException { loadFileData(); return new ByteArrayInputStream(data); }
private void add(int ch) { switch (ch) { case '\n': sourceFile.addLineOffset(offset + 1); break; case '\r': // Need to see next character to know if it's a // line terminator. break; default: if (lastSeen == '\r') { // We consider a bare CR to be an end of line // if it is not followed by a new line. // Mac OS has historically used a bare CR as // its line terminator. sourceFile.addLineOffset(offset); } } lastSeen = ch; ++offset; } }
String pkgName = line.getPackageName(); try { fullPath = sourceFinder.findSourceFile(pkgName, line.getSourceFile()).getFullFileName(); } catch (IOException e) { if ("".equals(pkgName)) {
/** * Open an input stream on a source file in given package. * * @param packageName * the name of the package containing the class whose source file * is given * @param fileName * the unqualified name of the source file * @return an InputStream on the source file * @throws IOException * if a matching source file cannot be found */ public InputStream openSource(String packageName, String fileName) throws IOException { SourceFile sourceFile = findSourceFile(packageName, fileName); return sourceFile.getInputStream(); }
/** * Get the byte offset in the data for a source line. Note that lines are * considered to be zero-index, so the first line in the file is numbered * zero. * * @param line * the line number * @return the byte offset in the file's data for the line, or -1 if the * line is not valid */ public int getLineOffset(int line) { try { loadFileData(); } catch (IOException e) { System.err.println("SourceFile.getLineOffset: " + e.getMessage()); return -1; } if (line < 0 || line >= numLines) { return -1; } return lineNumberMap[line]; }
/** * A zip or jar archive containing source files. */ static class ZipSourceRepository implements SourceRepository { ZipFile zipFile; public ZipSourceRepository(ZipFile zipFile) { this.zipFile = zipFile; } @Override public boolean contains(String fileName) { return zipFile.getEntry(fileName) != null; } @Override public boolean isPlatformDependent() { return false; } @Override public SourceFileDataSource getDataSource(String fileName) { return new ZipSourceFileDataSource(zipFile, fileName); } }
try { SourceFinder mySourceFinder = project.getSourceFinder(); String fullPath = new File(mySourceFinder.findSourceFile(this).getFullFileName()).getCanonicalPath(); String myRelativeSourceBase = relativeSourceBase.get(); if (fullPath.startsWith(myRelativeSourceBase) && fullPath.length() > myRelativeSourceBase.length()) {