-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added component to download web page; plus test network
- Loading branch information
Showing
17 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/jpaulmorrison/fbp/core/components/httpurl/LoadURL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.jpaulmorrison.fbp.core.components.httpurl; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
import com.jpaulmorrison.fbp.core.engine.Component; | ||
import com.jpaulmorrison.fbp.core.engine.InPort; | ||
import com.jpaulmorrison.fbp.core.engine.InputPort; | ||
import com.jpaulmorrison.fbp.core.engine.OutPort; | ||
import com.jpaulmorrison.fbp.core.engine.OutputPort; | ||
import com.jpaulmorrison.fbp.core.engine.Packet; | ||
|
||
//https://www.codejava.net/java-se/networking/use-httpurlconnection-to-download-file-from-an-http-url | ||
|
||
@InPort(value = "SOURCE", description = "HTMLName") | ||
@OutPort(value = "OUT", description = "HTML") | ||
|
||
public class LoadURL extends Component { | ||
|
||
private InputPort inPort; | ||
private OutputPort outPort; | ||
|
||
protected void execute() throws Exception { | ||
|
||
Packet<?> pp = inPort.receive(); | ||
|
||
String fileURL = (String) pp.getContent(); | ||
drop(pp); | ||
inPort.close(); | ||
|
||
|
||
// https://stackoverflow.com/questions/2793168/reading-httpurlconnection-inputstream-manual-buffer-or-bufferedinputstream | ||
|
||
URL url = new URL(fileURL); | ||
|
||
//HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); | ||
|
||
InputStream in = url.openStream(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); | ||
StringBuilder result = new StringBuilder(); | ||
String line = null; | ||
while((line = reader.readLine()) != null) { | ||
result.append(line); | ||
} | ||
outPort.send(create(result.toString())); | ||
reader.close(); | ||
} | ||
|
||
@Override | ||
protected void openPorts() { | ||
inPort = openInput("SOURCE"); | ||
outPort = openOutput("OUT"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/jpaulmorrison/fbp/resourcekit/examples/networks/ReadHTML.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* JavaFBP - A Java Implementation of Flow-Based Programming (FBP) | ||
* Copyright (C) 2009, 2016 J. Paul Morrison | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU Library General Public | ||
* License along with this library; if not, see the GNU Library General Public License v3 | ||
* at https://www.gnu.org/licenses/lgpl-3.0.en.html for more details. | ||
*/ | ||
|
||
package com.jpaulmorrison.fbp.resourcekit.examples.networks; | ||
|
||
|
||
|
||
|
||
import com.jpaulmorrison.fbp.core.components.httpurl.LoadURL; | ||
import com.jpaulmorrison.fbp.core.components.misc.WriteToConsole; | ||
import com.jpaulmorrison.fbp.core.engine.Network; | ||
|
||
/** | ||
* Read from URL; write to the console | ||
* | ||
*/ | ||
|
||
|
||
public class ReadHTML extends Network { | ||
|
||
@Override | ||
protected void define() { | ||
connect(component("Load URL", LoadURL.class), port("OUT"), component("Write", WriteToConsole.class), port("IN"), 1); | ||
initialize("https://github.com/jpaulm/javafbp/blob/master/README.md", component("Load URL"), port("SOURCE")); | ||
|
||
} | ||
|
||
public static void main(final String[] argv) throws Exception { | ||
new ReadHTML().go(); | ||
} | ||
} |