Browse Source

use simpler static method

tags/2.0.1
Jonathan Cobb 4 years ago
parent
commit
699a94f9df
2 changed files with 4 additions and 6 deletions
  1. +3
    -5
      src/main/java/bubble/abp/BlockListSource.java
  2. +1
    -1
      src/test/java/bubble/abp/spec/SelectorTest.java

+ 3
- 5
src/main/java/bubble/abp/BlockListSource.java View File

@@ -5,7 +5,6 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.cobbzilla.util.http.HttpUtil;

import java.io.BufferedReader;
import java.io.IOException;
@@ -13,7 +12,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;

import static org.cobbzilla.util.daemon.ZillaRuntime.*;
import static org.cobbzilla.util.daemon.ZillaRuntime.now;
import static org.cobbzilla.util.http.HttpUtil.getUrlInputStream;
import static org.cobbzilla.util.io.FileUtil.basename;

@NoArgsConstructor @Accessors(chain=true) @Slf4j
@@ -38,11 +37,10 @@ public class BlockListSource {

@Getter @Setter private BlockList blockList = new BlockList();

public InputStream getUrlInputStream() throws IOException { return getUrlInputStream(url); }
public static InputStream getUrlInputStream(String url) throws IOException { return HttpUtil.get(url); }
public InputStream urlInputStream() throws IOException { return getUrlInputStream(url); }

public BlockListSource download() throws IOException {
try (BufferedReader r = new BufferedReader(new InputStreamReader(getUrlInputStream()))) {
try (BufferedReader r = new BufferedReader(new InputStreamReader(urlInputStream()))) {
String line;
boolean firstLine = true;
int lineNumber = 1;


+ 1
- 1
src/test/java/bubble/abp/spec/SelectorTest.java View File

@@ -170,7 +170,7 @@ public class SelectorTest {
@Test public void testComplexList () throws Exception {
try {
final BlockListSource source = new BlockListSource() {
@Override public InputStream getUrlInputStream() { return loadResourceAsStream("AntiMalwareABP.txt"); }
@Override public InputStream urlInputStream() { return loadResourceAsStream("AntiMalwareABP.txt"); }
}.download();
assertEquals("error parsing some lines", 0, source.getBlockList().getWhitelist().size());
assertEquals("error parsing some lines", 553, source.getBlockList().getBlacklist().size());


Loading…
Cancel
Save