/** * Reads a stream of messages. This method returns an empty iterator if there are no messages. An * exception is raised on IO error, if file does not exist or if messages have a * different type than {@code parser}. */ public static <MSG extends Message> CloseableIterator<MSG> readStream(File file, Parser<MSG> parser) { try { // the input stream is closed by the CloseableIterator BufferedInputStream input = new BufferedInputStream(new FileInputStream(file)); return readStream(input, parser); } catch (Exception e) { throw ContextException.of("Unable to read messages", e).addContext("file", file); } }
public File writeComponentIssues(int componentRef, Iterable<ScannerReport.Issue> issues) { File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef); Protobuf.writeStream(issues, file, false); return file; }
public ScannerReport.Metadata readMetadata() { File file = fileStructure.metadataFile(); if (!fileExists(file)) { throw new IllegalStateException("Metadata file is missing in analysis report: " + file); } return Protobuf.read(file, ScannerReport.Metadata.parser()); }
@Test public void write_and_read_streams() throws Exception { File file = temp.newFile(); Fake item1 = Fake.newBuilder().setLabel("one").setLine(1).build(); Fake item2 = Fake.newBuilder().setLabel("two").build(); Protobuf.writeStream(asList(item1, item2), file, false); CloseableIterator<Fake> it = Protobuf.readStream(file, Fake.parser()); Fake read = it.next(); assertThat(read.getLabel()).isEqualTo("one"); assertThat(read.getLine()).isEqualTo(1); read = it.next(); assertThat(read.getLabel()).isEqualTo("two"); assertThat(read.hasLine()).isFalse(); assertThat(it.hasNext()).isFalse(); }
public File writeComponentChangedLines(int componentRef, ScannerReport.ChangedLines changedLines) { File file = fileStructure.fileFor(FileStructure.Domain.CHANGED_LINES, componentRef); Protobuf.write(changedLines, file); return file; }
private static Function<EventDto, EventDto> updateNameAndDescription(UpdateEventRequest request) { return event -> { setNullable(request.getName(), event::setName); return event; }; }
/** * Metadata is mandatory */ public File writeMetadata(ScannerReport.Metadata metadata) { Protobuf.write(metadata, fileStructure.metadataFile()); return fileStructure.metadataFile(); }
private static WsProjectResponse.FileData toFileDataResponse(FileData fileData) { Builder fileDataBuilder = WsProjectResponse.FileData.newBuilder(); setNullable(fileData.hash(), fileDataBuilder::setHash); setNullable(fileData.revision(), fileDataBuilder::setRevision); return fileDataBuilder.build(); } }
@CheckForNull public CloseableIterator<ScannerReport.LineSgnificantCode> readComponentSignificantCode(int fileRef) { File file = fileStructure.fileFor(FileStructure.Domain.SGNIFICANT_CODE, fileRef); if (fileExists(file)) { return Protobuf.readStream(file, ScannerReport.LineSgnificantCode.parser()); } return null; }
public File writeCpdTextBlocks(int componentRef, Iterable<ScannerReport.CpdTextBlock> blocks) { File file = fileStructure.fileFor(FileStructure.Domain.CPD_TEXT_BLOCKS, componentRef); Protobuf.writeStream(blocks, file, false); return file; }
public ScannerReport.Component readComponent(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, componentRef); if (!fileExists(file)) { throw new IllegalStateException("Unable to find report for component #" + componentRef + ". File does not exist: " + file); } return Protobuf.read(file, ScannerReport.Component.parser()); }
public File writeComponentChangesets(ScannerReport.Changesets changesets) { File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, changesets.getComponentRef()); Protobuf.write(changesets, file); return file; }
private Event.Builder dbToWsEvent(EventDto dbEvent) { wsEvent.clear().setKey(dbEvent.getUuid()); setNullable(dbEvent.getName(), wsEvent::setName); setNullable(dbEvent.getDescription(), wsEvent::setDescription); setNullable(dbEvent.getCategory(), cat -> wsEvent.setCategory(fromLabel(cat).name())); return wsEvent; }
public CloseableIterator<ScannerReport.ActiveRule> readActiveRules() { File file = fileStructure.activeRules(); if (!fileExists(file)) { return emptyCloseableIterator(); } return Protobuf.readStream(file, ScannerReport.ActiveRule.parser()); }
public File writeComponentSymbols(int componentRef, Iterable<ScannerReport.Symbol> symbols) { File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef); Protobuf.writeStream(symbols, file, false); return file; }
@CheckForNull public ScannerReport.ChangedLines readComponentChangedLines(int fileRef) { File file = fileStructure.fileFor(FileStructure.Domain.CHANGED_LINES, fileRef); if (fileExists(file)) { return Protobuf.read(file, ScannerReport.ChangedLines.parser()); } return null; }
public File writeComponent(ScannerReport.Component component) { File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, component.getRef()); Protobuf.write(component, file); return file; }
Organization.Builder toOrganization(Organization.Builder builder, OrganizationDto dto) { builder .setName(dto.getName()) .setKey(dto.getKey()) .setGuarded(dto.isGuarded()); setNullable(dto.getDescription(), builder::setDescription); setNullable(dto.getUrl(), builder::setUrl); setNullable(dto.getAvatarUrl(), builder::setAvatar); return builder; } }
public CloseableIterator<ScannerReport.AdHocRule> readAdHocRules() { File file = fileStructure.adHocRules(); if (!fileExists(file)) { return emptyCloseableIterator(); } return Protobuf.readStream(file, ScannerReport.AdHocRule.parser()); }