Work on this assignment is going so freaking slow
This commit is contained in:
parent
9ef4210608
commit
af97eb2bc8
@ -1 +0,0 @@
|
||||
,caleb,caleb-gaming-laptop-archlinux,20.10.2023 21:26,file:///home/caleb/.config/libreoffice/4;
|
Binary file not shown.
@ -0,0 +1,286 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>AddressBookFX.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST2 {color: #ffc66d}
|
||||
.ST5 {color: #9876aa}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST4 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/AddressBookFX.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.io.File;
|
||||
<span class="literal">import</span> java.io.FileInputStream;
|
||||
<span class="literal">import</span> java.io.FileOutputStream;
|
||||
<span class="literal">import</span> java.io.IOException;
|
||||
<span class="literal">import</span> java.io.ObjectInputStream;
|
||||
<span class="literal">import</span> java.io.ObjectOutputStream;
|
||||
<span class="literal">import</span> java.io.Serializable;
|
||||
<span class="literal">import</span> java.util.ArrayList;
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="comment">import</span> <span class="comment">javafx</span><span class="comment">.</span><span class="comment">geometry</span><span class="comment">.</span><span class="comment">HPos</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> javafx.geometry.Pos;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.control.Button;
|
||||
<span class="literal">import</span> javafx.scene.control.Label;
|
||||
<span class="literal">import</span> javafx.scene.control.TextField;
|
||||
<span class="literal">import</span> javafx.scene.layout.ColumnConstraints;
|
||||
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||||
<span class="comment">import</span> <span class="comment">javafx</span><span class="comment">.</span><span class="comment">scene</span><span class="comment">.</span><span class="comment">layout</span><span class="comment">.</span><span class="comment">RowConstraints</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> javafx.stage.Stage;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> AddressBookFX <span class="literal">extends</span> Application {
|
||||
|
||||
<span class="literal">static</span> File <span class="ST1">addressBook</span> = <span class="literal">new</span> File(<span class="string">"</span><span class="string">AddressBookFX.dat</span><span class="string">"</span>);
|
||||
<span class="literal">static</span> <span class="literal">int</span> <span class="ST1">addressArrayPointer</span> = <span class="number">0</span>;
|
||||
<span class="literal">static</span> ArrayList<AddressBookEntry> <span class="ST1">addressArray</span> = <span class="literal">new</span> ArrayList<>();
|
||||
<span class="literal">static</span> TextField <span class="ST1">nameTextField</span> = <span class="literal">new</span> TextField();
|
||||
<span class="literal">static</span> TextField <span class="ST1">streetTextField</span> = <span class="literal">new</span> TextField();
|
||||
<span class="literal">static</span> TextField <span class="ST1">cityTextField</span> = <span class="literal">new</span> TextField();
|
||||
<span class="literal">static</span> TextField <span class="ST1">stateTextField</span> = <span class="literal">new</span> TextField();
|
||||
<span class="literal">static</span> TextField <span class="ST1">zipTextField</span> = <span class="literal">new</span> TextField();
|
||||
<span class="literal">static</span> Label <span class="ST1">addressBookCounter</span> = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Items in address book:</span><span class="string">"</span>);
|
||||
<span class="literal">static</span> Label <span class="ST1">indexLabel</span> = <span class="literal">new</span> Label();
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">start</span>(Stage stage) <span class="literal">throws</span> Exception
|
||||
{
|
||||
<span class="ST3">getData</span>();
|
||||
BorderPane primaryBorderPane = <span class="literal">new</span> BorderPane();
|
||||
GridPane textFieldGridPane = <span class="literal">new</span> GridPane();
|
||||
GridPane addressFieldPane = <span class="literal">new</span> GridPane();
|
||||
GridPane buttonFieldPane = <span class="literal">new</span> GridPane();
|
||||
|
||||
<span class="comment">// Text fields / labels</span>
|
||||
textFieldGridPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Name</span><span class="string">"</span>), <span class="number">0</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">Street</span><span class="string">"</span>), <span class="number">0</span>, <span class="number">1</span>);
|
||||
textFieldGridPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">City</span><span class="string">"</span>), <span class="number">0</span>, <span class="number">2</span>);
|
||||
addressFieldPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">State</span><span class="string">"</span>), <span class="number">2</span>, <span class="number">0</span>);
|
||||
addressFieldPane.add(<span class="literal">new</span> Label(<span class="string">"</span><span class="string">ZIP</span><span class="string">"</span>), <span class="number">4</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.add(<span class="ST1">n</span><span class="ST1">ameTextField</span>, <span class="number">1</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.add(<span class="ST1">s</span><span class="ST1">treetTextField</span>, <span class="number">1</span>, <span class="number">1</span>);
|
||||
textFieldGridPane.add(addressFieldPane, <span class="number">1</span>, <span class="number">2</span>);
|
||||
addressFieldPane.add(<span class="ST1">c</span><span class="ST1">ityTextField</span>, <span class="number">1</span>, <span class="number">0</span>);
|
||||
addressFieldPane.add(<span class="ST1">s</span><span class="ST1">tateTextField</span>, <span class="number">3</span>, <span class="number">0</span>);
|
||||
addressFieldPane.add(<span class="ST1">z</span><span class="ST1">ipTextField</span>, <span class="number">5</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.getColumnConstraints().add(<span class="literal">new</span> ColumnConstraints(<span class="number">5</span><span class="number">0</span>));
|
||||
primaryBorderPane.setTop(textFieldGridPane);
|
||||
|
||||
<span class="comment">// Buttons</span>
|
||||
Button addButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Add</span><span class="string">"</span>);
|
||||
Button firstButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">First</span><span class="string">"</span>);
|
||||
Button nextButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Next</span><span class="string">"</span>);
|
||||
Button previousButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Previous</span><span class="string">"</span>);
|
||||
Button lastButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Last</span><span class="string">"</span>);
|
||||
Button updateButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Update</span><span class="string">"</span>);
|
||||
buttonFieldPane.add(<span class="ST1">i</span><span class="ST1">ndexLabel</span>, <span class="number">0</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(addButton, <span class="number">1</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(firstButton, <span class="number">2</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(nextButton, <span class="number">3</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(previousButton, <span class="number">4</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(lastButton, <span class="number">5</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(updateButton, <span class="number">6</span>, <span class="number">0</span>);
|
||||
buttonFieldPane.add(<span class="ST1">a</span><span class="ST1">ddressBookCounter</span>, <span class="number">7</span>, <span class="number">0</span>);
|
||||
|
||||
primaryBorderPane.setBottom(buttonFieldPane);
|
||||
buttonFieldPane.setAlignment(Pos.<span class="ST1">CENTER</span>);
|
||||
buttonFieldPane.setHgap(<span class="number">1</span><span class="number">0</span>);
|
||||
|
||||
addButton.setOnAction(e -> {
|
||||
<span class="ST1">addressArray</span>.add(<span class="literal">new</span> AddressBookEntry());
|
||||
<span class="ST3">updateData</span>();
|
||||
});
|
||||
firstButton.setOnAction(e -> {
|
||||
<span class="ST1">addressArrayPointer</span> = <span class="number">0</span>;
|
||||
<span class="ST3">getEntry</span>(<span class="ST1">a</span><span class="ST1">ddressArrayPointer</span>);
|
||||
});
|
||||
nextButton.setOnAction(e -> {
|
||||
<span class="literal">if</span> (<span class="ST1">addressArrayPointer</span> >= <span class="ST1">addressArray</span>.size() - <span class="number">1</span>) {
|
||||
<span class="ST1">addressArrayPointer</span> = <span class="number">0</span>;
|
||||
} <span class="literal">else</span> {
|
||||
<span class="ST1">addressArrayPointer</span>++;
|
||||
}
|
||||
<span class="ST3">getEntry</span>(<span class="ST1">a</span><span class="ST1">ddressArrayPointer</span>);
|
||||
});
|
||||
previousButton.setOnAction(e -> {
|
||||
<span class="literal">if</span> (<span class="ST1">addressArrayPointer</span> > <span class="number">0</span>) {
|
||||
<span class="ST1">addressArrayPointer</span>--;
|
||||
} <span class="literal">else</span> {
|
||||
<span class="ST1">addressArrayPointer</span> = <span class="ST1">addressArray</span>.size() - <span class="number">1</span>;
|
||||
}
|
||||
<span class="ST3">getEntry</span>(<span class="ST1">a</span><span class="ST1">ddressArrayPointer</span>);
|
||||
});
|
||||
lastButton.setOnAction(e -> {
|
||||
<span class="ST1">addressArrayPointer</span> = <span class="ST1">addressArray</span>.size() - <span class="number">1</span>;
|
||||
<span class="ST3">getEntry</span>(<span class="ST1">a</span><span class="ST1">ddressArrayPointer</span>);
|
||||
});
|
||||
updateButton.setOnAction(e -> {
|
||||
AddressBookEntry entry = <span class="ST1">addressArray</span>.get(<span class="ST1">a</span><span class="ST1">ddressArrayPointer</span>);
|
||||
entry.setName(<span class="ST1">n</span><span class="ST1">ameTextField</span>.getText());
|
||||
entry.setCity(<span class="ST1">n</span><span class="ST1">ameTextField</span>.getText());
|
||||
entry.setStreet(<span class="ST1">s</span><span class="ST1">treetTextField</span>.getText());
|
||||
entry.setCity(<span class="ST1">c</span><span class="ST1">ityTextField</span>.getText());
|
||||
entry.setState(<span class="ST1">s</span><span class="ST1">tateTextField</span>.getText());
|
||||
entry.setZip(<span class="ST1">z</span><span class="ST1">ipTextField</span>.getText());
|
||||
<span class="ST3">updateData</span>();
|
||||
});
|
||||
|
||||
<span class="comment">// init fields with data from first entry</span>
|
||||
<span class="ST3">getEntry</span>(<span class="number">0</span>);
|
||||
|
||||
Scene scene = <span class="literal">new</span> Scene(primaryBorderPane);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> AddressBookEntry <span class="ST4">getEntry</span>(<span class="literal">int</span> index)
|
||||
{
|
||||
AddressBookEntry entry = <span class="ST1">addressArray</span>.get(index);
|
||||
<span class="ST1">indexLabel</span>.setText(<span class="string">"</span><span class="string">Current index: </span><span class="string">"</span> + index);
|
||||
<span class="ST1">addressBookCounter</span>.setText(<span class="string">"</span><span class="string">Items in address book: </span><span class="string">"</span> + <span class="ST1">addressArray</span>.size());
|
||||
<span class="ST1">nameTextField</span>.setText(entry.getName());
|
||||
<span class="ST1">streetTextField</span>.setText(entry.getStreet());
|
||||
<span class="ST1">cityTextField</span>.setText(entry.getCity());
|
||||
<span class="ST1">stateTextField</span>.setText(entry.getState());
|
||||
<span class="ST1">zipTextField</span>.setText(entry.getZip());
|
||||
<span class="literal">return</span> entry;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">updateData</span>()
|
||||
{
|
||||
<span class="literal">try</span> (ObjectOutputStream fileStream = <span class="literal">new</span> ObjectOutputStream(<span class="literal">new</span> FileOutputStream(<span class="ST1">a</span><span class="ST1">ddressBook</span>))) {
|
||||
fileStream.writeObject(<span class="ST1">a</span><span class="ST1">ddressArray</span>);
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST1">out</span>.println(ex);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">getData</span>()
|
||||
{
|
||||
<span class="literal">if</span> (!<span class="ST1">addressBook</span>.exists()) {
|
||||
<span class="ST1">addressArray</span>.add(<span class="literal">new</span> AddressBookEntry());
|
||||
<span class="ST3">updateData</span>();
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">try</span> (ObjectInputStream fileStream = <span class="literal">new</span> ObjectInputStream(<span class="literal">new</span> FileInputStream(<span class="ST1">a</span><span class="ST1">ddressBook</span>))) {
|
||||
<span class="ST1">addressArray</span> = (ArrayList<AddressBookEntry>) fileStream.readObject();
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST1">out</span>.println(ex);
|
||||
} <span class="literal">catch</span> (ClassNotFoundException ex) {
|
||||
System.<span class="ST1">out</span>.println(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">main</span>(String[] args)
|
||||
{
|
||||
<span class="ST3">launch</span>();
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">class</span> AddressBookEntry <span class="literal">implements</span> Serializable {
|
||||
|
||||
<span class="literal">private</span> String <span class="ST5">name</span>;
|
||||
<span class="literal">private</span> String <span class="ST5">street</span>;
|
||||
<span class="literal">private</span> String <span class="ST5">city</span>;
|
||||
<span class="literal">private</span> String <span class="ST5">state</span>;
|
||||
<span class="literal">private</span> String <span class="ST5">zip</span>;
|
||||
|
||||
<span class="literal">public</span> AddressBookEntry()
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">name</span> = <span class="string">"</span><span class="string">Enter a name here.</span><span class="string">"</span>;
|
||||
<span class="literal">this</span>.<span class="ST5">street</span> = <span class="string">"</span><span class="string">Enter a street here.</span><span class="string">"</span>;
|
||||
<span class="literal">this</span>.<span class="ST5">city</span> = <span class="string">"</span><span class="string">Enter a city here.</span><span class="string">"</span>;
|
||||
<span class="literal">this</span>.<span class="ST5">state</span> = <span class="string">"</span><span class="string">Enter a state here.</span><span class="string">"</span>;
|
||||
<span class="literal">this</span>.<span class="ST5">zip</span> = <span class="string">"</span><span class="string">Enter a zip here.</span><span class="string">"</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> AddressBookEntry(String name, String street, String city, String state, String zip)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">name</span> = name;
|
||||
<span class="literal">this</span>.<span class="ST5">street</span> = street;
|
||||
<span class="literal">this</span>.<span class="ST5">city</span> = city;
|
||||
<span class="literal">this</span>.<span class="ST5">state</span> = state;
|
||||
<span class="literal">this</span>.<span class="ST5">zip</span> = zip;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST2">getZip</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST5">zip</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setZip</span>(String zip)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">zip</span> = zip;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST2">getState</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST5">state</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setState</span>(String state)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">state</span> = state;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST2">getCity</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST5">city</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setCity</span>(String city)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">city</span> = city;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST2">getStreet</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST5">street</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setStreet</span>(String street)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">street</span> = street;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST2">getName</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST5">name</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setName</span>(String name)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST5">name</span> = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,160 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>CombineFilesFX.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST3 {color: #9876aa}
|
||||
.ST4 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
.ST1 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/CombineFilesFX.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">io</span><span class="comment">.</span><span class="comment">DataInput</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> java.io.File;
|
||||
<span class="literal">import</span> java.io.FileInputStream;
|
||||
<span class="literal">import</span> java.io.FileOutputStream;
|
||||
<span class="literal">import</span> java.io.IOException;
|
||||
<span class="literal">import</span> java.util.ArrayList;
|
||||
<span class="literal">import</span> java.util.Collections;
|
||||
<span class="literal">import</span> java.util.Comparator;
|
||||
<span class="literal">import</span> java.util.List;
|
||||
<span class="literal">import</span> java.util.regex.Matcher;
|
||||
<span class="literal">import</span> java.util.regex.Pattern;
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="literal">import</span> javafx.geometry.Pos;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.control.Alert;
|
||||
<span class="literal">import</span> javafx.scene.control.Alert.<span class="ST1">AlertType</span>;
|
||||
<span class="literal">import</span> javafx.scene.control.Button;
|
||||
<span class="literal">import</span> javafx.scene.control.Label;
|
||||
<span class="comment">import</span> <span class="comment">javafx</span><span class="comment">.</span><span class="comment">scene</span><span class="comment">.</span><span class="comment">control</span><span class="comment">.</span><span class="comment">TextField</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
||||
<span class="literal">import</span> javafx.stage.FileChooser;
|
||||
<span class="literal">import</span> javafx.stage.Stage;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> CombineFilesFX <span class="literal">extends</span> Application {
|
||||
|
||||
<span class="literal">static</span> ArrayList<File> <span class="ST2">files</span> = <span class="literal">new</span> ArrayList<File>();
|
||||
<span class="literal">final</span> FileChooser <span class="ST3">fileChooser</span> = <span class="literal">new</span> FileChooser();
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST4">start</span>(<span class="literal">final</span> Stage stage) <span class="literal">throws</span> Exception {
|
||||
<span class="ST3">fileChooser</span>.setTitle(<span class="string">"</span><span class="string">Open File to Split...</span><span class="string">"</span>);
|
||||
BorderPane primaryBorderPane = <span class="literal">new</span> BorderPane();
|
||||
GridPane textFieldGridPane = <span class="literal">new</span> GridPane();
|
||||
|
||||
Label infoLabel = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Point me at the files that were output by SplitFilesFX.java.</span><span class="string">"</span>);
|
||||
Label chooseFile = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Choose files to combine: </span><span class="string">"</span>);
|
||||
Button openFilePicker = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Choose...</span><span class="string">"</span>);
|
||||
Button run = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Start</span><span class="string">"</span>);
|
||||
textFieldGridPane.add(chooseFile, <span class="number">0</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.add(openFilePicker, <span class="number">1</span>, <span class="number">0</span>);
|
||||
primaryBorderPane.<span class="ST1">setAlignment</span>(run, Pos.<span class="ST2">CENTER</span>);
|
||||
|
||||
primaryBorderPane.setTop(infoLabel);
|
||||
primaryBorderPane.setCenter(textFieldGridPane);
|
||||
primaryBorderPane.setBottom(run);
|
||||
|
||||
openFilePicker.setOnAction(e -> {
|
||||
<span class="comment">// When we initially get the files from the file chooser, it returns an unsortable list. Because of this, we need to create a new List with its data.</span>
|
||||
<span class="ST2">files</span>.addAll(<span class="ST3">f</span><span class="ST3">ileChooser</span>.showOpenMultipleDialog(openFilePicker.getScene().getWindow()));
|
||||
<span class="comment">// The file picker appears to return files in a random order, so we need to sort them by file name.</span>
|
||||
Collections.<span class="ST1">sort</span>(<span class="ST2">f</span><span class="ST2">iles</span>, <span class="literal">new</span> Comparator<File>() {
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST4">compare</span>(File o1, File o2) {
|
||||
<span class="literal">return</span> extractInt(o1.getName()) - extractInt(o2.getName());
|
||||
}
|
||||
|
||||
String <span class="ST4">findMatch</span>(String s) {
|
||||
Pattern findNum = Pattern.<span class="ST1">compile</span>(<span class="string">"</span><span class="literal">\\</span><span class="string">d+$</span><span class="string">"</span>);
|
||||
Matcher match = findNum.matcher(s);
|
||||
<span class="literal">while</span> (match.find()) {
|
||||
<span class="literal">return</span> match.group();
|
||||
}
|
||||
<span class="literal">return</span> <span class="string">""</span>;
|
||||
}
|
||||
|
||||
<span class="literal">int</span> <span class="ST4">extractInt</span>(String s) {
|
||||
String num = findMatch(s);
|
||||
System.<span class="ST2">out</span>.println(num);
|
||||
<span class="comment">// return 0 if no digits found</span>
|
||||
<span class="literal">return</span> num.isEmpty() ? <span class="number">0</span> : Integer.<span class="ST1">parseInt</span>(num);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
run.setOnAction(e -> {
|
||||
<span class="literal">if</span> (<span class="ST2">files</span> == <span class="literal">null</span>) {
|
||||
e.consume();
|
||||
}
|
||||
<span class="ST1">combineFiles</span>(<span class="ST2">f</span><span class="ST2">iles</span>);
|
||||
});
|
||||
|
||||
Scene scene = <span class="literal">new</span> Scene(primaryBorderPane);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">combineFiles</span>(List<File> filesToCombine) {
|
||||
String outputPath = filesToCombine.get(<span class="number">0</span>).getParent();
|
||||
<span class="literal">try</span> (FileOutputStream dataOut = <span class="literal">new</span> FileOutputStream(outputPath + <span class="string">"</span><span class="string">/</span><span class="string">"</span> + <span class="string">"</span><span class="string">reconstructed_</span><span class="string">"</span> + filesToCombine.get(<span class="number">0</span>).getName().substring(<span class="number">0</span>, (filesToCombine.get(<span class="number">0</span>).getName().length() - <span class="number">2</span>)))) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Writing to </span><span class="string">"</span> + outputPath + <span class="string">"</span><span class="string">/</span><span class="string">"</span> + <span class="string">"</span><span class="string">reconstructed_</span><span class="string">"</span> + filesToCombine.get(<span class="number">0</span>).getName().substring(<span class="number">0</span>, (filesToCombine.get(<span class="number">0</span>).getName().length() - <span class="number">2</span>)));
|
||||
<span class="literal">for</span> (File file : filesToCombine) {
|
||||
<span class="literal">try</span> (FileInputStream dataIn = <span class="literal">new</span> FileInputStream(file)) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Opening the source file </span><span class="string">"</span> + file.getName() + <span class="string">"</span><span class="string">!</span><span class="string">"</span>);
|
||||
<span class="literal">byte</span>[] buffer = <span class="literal">new</span> <span class="literal">byte</span>[<span class="number">4096</span>];
|
||||
<span class="literal">int</span> bytesRead = -<span class="number">1</span>;
|
||||
|
||||
<span class="literal">while</span> ((bytesRead = dataIn.read(buffer)) != -<span class="number">1</span>) {
|
||||
dataOut.write(buffer, <span class="number">0</span>, bytesRead);
|
||||
}
|
||||
}
|
||||
<span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST2">out</span>.println(ex);
|
||||
}
|
||||
}
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST2">out</span>.println(ex);
|
||||
}
|
||||
Alert alert = <span class="literal">new</span> Alert(<span class="ST1">A</span><span class="ST1">lertType</span>.<span class="ST2">INFORMATION</span>);
|
||||
alert.setTitle(<span class="string">"</span><span class="string">Success!</span><span class="string">"</span>);
|
||||
alert.setContentText(<span class="string">"</span><span class="string">Successfully combined the files!</span><span class="string">"</span>);
|
||||
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) {
|
||||
<span class="ST1">launch</span>();
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Exercise17_01.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/Exercise17_01.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.io.EOFException;
|
||||
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">io</span><span class="comment">.</span><span class="comment">FileNotFoundException</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> java.io.RandomAccessFile;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> Exercise17_01 {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args)
|
||||
{
|
||||
<span class="literal">try</span> (RandomAccessFile fileIO = <span class="literal">new</span> RandomAccessFile(<span class="string">"</span><span class="string">Exercise17_01.txt</span><span class="string">"</span>, <span class="string">"</span><span class="string">rw</span><span class="string">"</span>)) {
|
||||
<span class="literal">int</span> random = <span class="number">0</span>;
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Writing data to file...</span><span class="string">"</span>);
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">1</span>; i < <span class="number">100</span> + <span class="number">1</span>; ++i) {
|
||||
random = (<span class="literal">int</span>) (Math.<span class="ST3">random</span>() * <span class="number">9</span>) + <span class="number">1</span>;
|
||||
System.<span class="ST2">out</span>.print(random + <span class="string">"</span> <span class="string">"</span>);
|
||||
<span class="literal">if</span> (i != <span class="number">0</span> && i % <span class="number">10</span> == <span class="number">0</span>) {
|
||||
System.<span class="ST2">out</span>.println();
|
||||
}
|
||||
fileIO.writeInt(random);
|
||||
}
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Wrote to the file successfully!</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">File contents:</span><span class="string">"</span>);
|
||||
fileIO.seek(<span class="number">0</span>);
|
||||
<span class="literal">int</span> readIterator = <span class="number">1</span>;
|
||||
<span class="literal">while</span> (<span class="literal">true</span>) {
|
||||
<span class="literal">try</span> {
|
||||
System.<span class="ST2">out</span>.print(fileIO.readInt() + <span class="string">"</span> <span class="string">"</span>);
|
||||
<span class="literal">if</span> (readIterator != <span class="number">0</span> && readIterator % <span class="number">10</span> == <span class="number">0</span>) {
|
||||
System.<span class="ST2">out</span>.println();
|
||||
}
|
||||
++readIterator;
|
||||
} <span class="literal">catch</span> (EOFException e) {
|
||||
<span class="literal">break</span>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} <span class="literal">catch</span> (Exception ex) {
|
||||
System.<span class="ST2">out</span>.println(ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Exercise17_03.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/Exercise17_03.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.io.DataInputStream;
|
||||
<span class="literal">import</span> java.io.DataOutputStream;
|
||||
<span class="literal">import</span> java.io.FileInputStream;
|
||||
<span class="literal">import</span> java.io.FileOutputStream;
|
||||
<span class="literal">import</span> java.io.IOException;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> Exercise17_03 {
|
||||
|
||||
<span class="literal">static</span> <span class="literal">int</span> fileSize = Math.abs((<span class="literal">int</span>) (Math.random() * <span class="number">1024</span>));
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> writeData()
|
||||
{
|
||||
<span class="literal">try</span> (FileOutputStream fileWrite = <span class="literal">new</span> FileOutputStream(<span class="string">"</span><span class="string">Exercise17_03.dat</span><span class="string">"</span>)) {
|
||||
<span class="comment">// Write a unspecified number of integers into the file.</span>
|
||||
<span class="comment">// Must be positive!</span>
|
||||
<span class="literal">int</span> randInt = <span class="number">0</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < fileSize; ++i) {
|
||||
randInt = (<span class="literal">int</span>) (Math.random() * <span class="number">10</span>);
|
||||
fileWrite.write(randInt);
|
||||
}
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
System.out.println(<span class="string">"</span><span class="string">Wrote data to the file!</span><span class="string">"</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span>[] readData()
|
||||
{
|
||||
<span class="literal">int</span>[] fileData = <span class="literal">new</span> <span class="literal">int</span>[fileSize];
|
||||
<span class="literal">try</span> (FileInputStream fileRead = <span class="literal">new</span> FileInputStream(<span class="string">"</span><span class="string">Exercise17_03.dat</span><span class="string">"</span>)) {
|
||||
<span class="comment">// Read the data back</span>
|
||||
<span class="literal">int</span> dataIterator = <span class="number">0</span>;
|
||||
<span class="literal">int</span> dataStream = <span class="number">0</span>;
|
||||
<span class="literal">while</span> (fileRead.available() > <span class="number">0</span>) {
|
||||
dataStream = fileRead.read();
|
||||
fileData[dataIterator++] = dataStream;
|
||||
System.out.print(dataStream + <span class="string">"</span> <span class="string">"</span>);
|
||||
<span class="literal">if</span> ((dataIterator + <span class="number">1</span>) % <span class="number">10</span> == <span class="number">0</span>) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
<span class="literal">return</span> fileData;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="string">Ints to write: </span><span class="string">"</span> + fileSize);
|
||||
writeData();
|
||||
<span class="literal">int</span>[] fileData = readData();
|
||||
<span class="comment">// Sum the digits</span>
|
||||
<span class="literal">int</span> sum = <span class="number">0</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i: fileData) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println(<span class="string">"</span><span class="literal">\n</span><span class="string">The sum of the integers in the file is: </span><span class="string">"</span> + sum);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,107 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Exercise17_05.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST3 {color: #9876aa}
|
||||
.ST4 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/Exercise17_05.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.io.File;
|
||||
<span class="literal">import</span> java.io.FileInputStream;
|
||||
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">io</span><span class="comment">.</span><span class="comment">FileNotFoundException</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> java.io.FileOutputStream;
|
||||
<span class="literal">import</span> java.io.IOException;
|
||||
<span class="literal">import</span> java.io.ObjectInputStream;
|
||||
<span class="literal">import</span> java.io.Serializable;
|
||||
<span class="literal">import</span> java.io.ObjectOutputStream;
|
||||
<span class="literal">import</span> java.util.Date;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> Exercise17_05 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
File dataFile = <span class="literal">new</span> File(<span class="string">"</span><span class="string">Exercise17_05.dat</span><span class="string">"</span>);
|
||||
<span class="literal">if</span>(!dataFile.exists()) {
|
||||
<span class="literal">try</span> (ObjectOutputStream fileStream = <span class="literal">new</span> ObjectOutputStream(<span class="literal">new</span> FileOutputStream(dataFile))) {
|
||||
fileStream.writeObject(<span class="literal">new</span> DataContainer());
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST2">out</span>.println(ex);
|
||||
}
|
||||
}
|
||||
DataContainer data = <span class="literal">null</span>;
|
||||
<span class="literal">try</span> (ObjectInputStream fileStream = <span class="literal">new</span> ObjectInputStream(<span class="literal">new</span> FileInputStream(dataFile))) {
|
||||
data = (DataContainer) fileStream.readObject();
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST2">out</span>.println(ex);
|
||||
} <span class="literal">catch</span> (ClassNotFoundException ex) {
|
||||
System.<span class="ST2">out</span>.println(ex);
|
||||
}
|
||||
<span class="comment">// Now print out the data!</span>
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">We got the data from the file!</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">class</span> DataContainer <span class="literal">implements</span> Serializable {
|
||||
<span class="literal">int</span>[] <span class="ST3">intArray</span> = {<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>};
|
||||
Date <span class="ST3">currentDate</span> = <span class="literal">new</span> Date();
|
||||
<span class="literal">double</span> <span class="ST3">doubleMoment</span> = <span class="number">5.5</span>;
|
||||
|
||||
<span class="literal">public</span> <span class="literal">int</span>[] <span class="ST4">getIntArray</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST3">intArray</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> Date <span class="ST4">getCurrentDate</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST3">currentDate</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST4">getDoubleMoment</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST3">doubleMoment</span>;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> String <span class="ST4">toString</span>()
|
||||
{
|
||||
String intString = <span class="string">"</span><span class="string">[</span><span class="string">"</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="ST3">intArray</span>.<span class="ST3">length</span> - <span class="number">1</span>; ++i) {
|
||||
intString += <span class="ST3">intArray</span>[i];
|
||||
<span class="literal">if</span> (i == (<span class="ST3">intArray</span>.<span class="ST3">length</span> - <span class="number">2</span>)) {
|
||||
intString += <span class="string">"</span><span class="string">]</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> {
|
||||
intString += <span class="string">"</span><span class="string">, </span><span class="string">"</span>;
|
||||
}
|
||||
}
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">DataContainer{</span><span class="string">"</span> + <span class="string">"</span><span class="string">intArray=</span><span class="string">"</span> + intString + <span class="string">"</span><span class="string">, currentDate=</span><span class="string">"</span> + <span class="ST3">currentDate</span> + <span class="string">"</span><span class="string">, doubleMoment=</span><span class="string">"</span> + <span class="ST3">doubleMoment</span> + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;
|
||||
}
|
||||
}
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,177 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>HexEditorFX.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST1 {color: #9876aa}
|
||||
.ST3 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/HexEditorFX.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> <span class="literal">static</span> com.calebfontenot.mp5.files_calebfontenot.SplitFilesFX.alert;
|
||||
<span class="comment">import</span> <span class="comment">static</span> <span class="comment">com</span><span class="comment">.</span><span class="comment">calebfontenot</span><span class="comment">.</span><span class="comment">mp5</span><span class="comment">.</span><span class="comment">files_calebfontenot</span><span class="comment">.</span><span class="comment">SplitFilesFX</span><span class="comment">.</span><span class="comment">file</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> java.io.File;
|
||||
<span class="literal">import</span> java.io.FileInputStream;
|
||||
<span class="literal">import</span> java.io.FileNotFoundException;
|
||||
<span class="literal">import</span> java.io.FileOutputStream;
|
||||
<span class="literal">import</span> java.io.IOException;
|
||||
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">util</span><span class="comment">.</span><span class="comment">ArrayList</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="literal">import</span> javafx.geometry.Pos;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.control.Button;
|
||||
<span class="literal">import</span> javafx.scene.control.Label;
|
||||
<span class="literal">import</span> javafx.scene.control.TextArea;
|
||||
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
||||
<span class="literal">import</span> javafx.stage.FileChooser;
|
||||
<span class="literal">import</span> javafx.stage.Stage;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> HexEditorFX <span class="literal">extends</span> Application {
|
||||
|
||||
<span class="literal">final</span> FileChooser <span class="ST1">fileChooser</span> = <span class="literal">new</span> FileChooser();
|
||||
<span class="literal">static</span> File <span class="ST2">file</span> = <span class="literal">null</span>;
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST3">start</span>(Stage stage) <span class="literal">throws</span> Exception {
|
||||
Label label = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Open a file...</span><span class="string">"</span>);
|
||||
Button openFileButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Choose...</span><span class="string">"</span>);
|
||||
TextArea editorWindow = <span class="literal">new</span> TextArea();
|
||||
Button saveFileButton = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Save</span><span class="string">"</span>);
|
||||
|
||||
editorWindow.setWrapText(<span class="literal">t</span><span class="literal">rue</span>);
|
||||
|
||||
BorderPane bp = <span class="literal">new</span> BorderPane();
|
||||
GridPane openFileGridPane = <span class="literal">new</span> GridPane();
|
||||
|
||||
openFileGridPane.add(label, <span class="number">0</span>, <span class="number">0</span>);
|
||||
openFileGridPane.add(openFileButton, <span class="number">1</span>, <span class="number">0</span>);
|
||||
|
||||
bp.setTop(openFileGridPane);
|
||||
bp.setCenter(editorWindow);
|
||||
bp.setBottom(saveFileButton);
|
||||
bp.<span class="ST4">setAlignment</span>(saveFileButton, Pos.<span class="ST2">CENTER</span>);
|
||||
|
||||
openFileButton.setOnAction(e -> {
|
||||
<span class="ST2">file</span> = <span class="ST1">fileChooser</span>.showOpenDialog(openFileButton.getScene().getWindow());
|
||||
<span class="literal">byte</span>[] data = <span class="literal">null</span>;
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Getting data from fileand encoding it as hex...</span><span class="string">"</span>);
|
||||
<span class="literal">try</span> (FileInputStream dataIn = <span class="literal">new</span> FileInputStream(<span class="ST2">file</span>)) {
|
||||
data = dataIn.readAllBytes();
|
||||
} <span class="literal">catch</span> (FileNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
String dataString = encodeHexString(data);
|
||||
editorWindow.setText(dataString);
|
||||
});
|
||||
|
||||
saveFileButton.setOnAction(e -> {
|
||||
<span class="literal">if</span> (<span class="ST2">file</span> == <span class="literal">null</span>) {
|
||||
<span class="ST2">alert</span>.setTitle(<span class="string">"</span><span class="string">No file selected!</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.setHeaderText(<span class="string">"</span><span class="string">No file selected!</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.setContentText(<span class="string">"</span><span class="string">You have to open a file first, silly!</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.showAndWait();
|
||||
}
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Re-encoding hex back into a byte array...</span><span class="string">"</span>);
|
||||
|
||||
<span class="literal">try</span> (FileOutputStream dataOut = <span class="literal">new</span> FileOutputStream(<span class="ST2">file</span>)) {
|
||||
<span class="literal">byte</span>[] bytesToSave = decodeHexString(editorWindow.getText());
|
||||
dataOut.write(bytesToSave);
|
||||
} <span class="literal">catch</span> (FileNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} <span class="literal">catch</span> (IllegalArgumentException ex) {
|
||||
<span class="ST2">alert</span>.setTitle(<span class="string">"</span><span class="string">Invalid Hex!</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.setContentText(<span class="string">"</span><span class="string">Invalid hex entered into the text box, unable to save.</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.showAndWait();
|
||||
}
|
||||
<span class="ST2">alert</span>.setTitle(<span class="string">"</span><span class="string">Save successful!</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.setContentText(<span class="string">"</span><span class="string">File saved successfully.</span><span class="string">"</span>);
|
||||
<span class="ST2">alert</span>.showAndWait();
|
||||
});
|
||||
|
||||
Scene scene = <span class="literal">new</span> Scene(bp);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
|
||||
}
|
||||
|
||||
<span class="literal">private</span> <span class="literal">int</span> <span class="ST3">toDigit</span>(<span class="literal">char</span> hexChar) {
|
||||
<span class="literal">int</span> digit = Character.<span class="ST4">digit</span>(hexChar, <span class="number">1</span><span class="number">6</span>);
|
||||
<span class="literal">if</span> (digit == -<span class="number">1</span>) {
|
||||
<span class="literal">throw</span> <span class="literal">new</span> IllegalArgumentException(
|
||||
<span class="string">"</span><span class="string">Invalid Hexadecimal Character: </span><span class="string">"</span> + hexChar);
|
||||
}
|
||||
<span class="literal">return</span> digit;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">byte</span> <span class="ST3">hexToByte</span>(String hexString) {
|
||||
<span class="literal">int</span> firstDigit = toDigit(hexString.charAt(<span class="number">0</span>));
|
||||
<span class="literal">int</span> secondDigit = toDigit(hexString.charAt(<span class="number">1</span>));
|
||||
<span class="literal">return</span> (<span class="literal">byte</span>) ((firstDigit << <span class="number">4</span>) + secondDigit);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">byte</span>[] <span class="ST3">decodeHexString</span>(String hexString) {
|
||||
<span class="literal">if</span> (hexString.length() % <span class="number">2</span> == <span class="number">1</span>) {
|
||||
<span class="literal">throw</span> <span class="literal">new</span> IllegalArgumentException(
|
||||
<span class="string">"</span><span class="string">Invalid hexadecimal String supplied.</span><span class="string">"</span>);
|
||||
}
|
||||
<span class="literal">byte</span>[] bytes = <span class="literal">new</span> <span class="literal">byte</span>[hexString.length() / <span class="number">2</span>];
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < hexString.length(); i += <span class="number">2</span>) {
|
||||
bytes[i / <span class="number">2</span>] = hexToByte(hexString.substring(i, i + <span class="number">2</span>));
|
||||
}
|
||||
<span class="literal">return</span> bytes;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST3">byteToHex</span>(<span class="literal">byte</span> num) {
|
||||
<span class="literal">char</span>[] hexDigits = <span class="literal">new</span> <span class="literal">char</span>[<span class="number">2</span>];
|
||||
hexDigits[<span class="number">0</span>] = Character.<span class="ST4">forDigit</span>((num >> <span class="number">4</span>) & <span class="number">0xF</span>, <span class="number">1</span><span class="number">6</span>);
|
||||
hexDigits[<span class="number">1</span>] = Character.<span class="ST4">forDigit</span>((num & <span class="number">0xF</span>), <span class="number">1</span><span class="number">6</span>);
|
||||
<span class="literal">return</span> <span class="literal">new</span> String(hexDigits);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> String <span class="ST3">encodeHexString</span>(<span class="literal">byte</span>[] byteArray) {
|
||||
StringBuffer hexStringBuffer = <span class="literal">new</span> StringBuffer();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < byteArray.<span class="ST1">length</span>; i++) {
|
||||
hexStringBuffer.append(byteToHex(byteArray[i]));
|
||||
}
|
||||
<span class="literal">return</span> hexStringBuffer.toString();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) {
|
||||
<span class="ST4">launch</span>(args);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,152 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>SplitFilesFX.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST2 {color: #9876aa}
|
||||
.ST4 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/SplitFilesFX.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">io</span><span class="comment">.</span><span class="comment">DataInput</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> java.io.File;
|
||||
<span class="literal">import</span> java.io.FileInputStream;
|
||||
<span class="literal">import</span> java.io.FileOutputStream;
|
||||
<span class="literal">import</span> java.io.IOException;
|
||||
<span class="literal">import</span> javafx.application.Application;
|
||||
<span class="literal">import</span> javafx.geometry.Pos;
|
||||
<span class="literal">import</span> javafx.scene.Scene;
|
||||
<span class="literal">import</span> javafx.scene.control.Alert;
|
||||
<span class="literal">import</span> javafx.scene.control.Button;
|
||||
<span class="literal">import</span> javafx.scene.control.Label;
|
||||
<span class="literal">import</span> javafx.scene.control.ProgressBar;
|
||||
<span class="literal">import</span> javafx.scene.control.TextField;
|
||||
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||||
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
||||
<span class="literal">import</span> javafx.stage.FileChooser;
|
||||
<span class="literal">import</span> javafx.stage.Stage;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> SplitFilesFX <span class="literal">extends</span> Application {
|
||||
<span class="literal">static</span> File <span class="ST1">file</span> = <span class="literal">null</span>;
|
||||
<span class="literal">final</span> FileChooser <span class="ST2">fileChooser</span> = <span class="literal">new</span> FileChooser();
|
||||
<span class="literal">static</span> ProgressBar <span class="ST1">pb</span> = <span class="literal">new</span> ProgressBar();
|
||||
<span class="literal">static</span> Alert <span class="ST1">alert</span> = <span class="literal">new</span> Alert(Alert.<span class="ST3">AlertType</span>.<span class="ST1">INFORMATION</span>);
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST4">start</span>(<span class="literal">final</span> Stage stage) <span class="literal">throws</span> Exception
|
||||
{
|
||||
<span class="ST2">fileChooser</span>.setTitle(<span class="string">"</span><span class="string">Open File to Split...</span><span class="string">"</span>);
|
||||
BorderPane primaryBorderPane = <span class="literal">new</span> BorderPane();
|
||||
BorderPane secondaryBoarderPane = <span class="literal">new</span> BorderPane();
|
||||
GridPane textFieldGridPane = <span class="literal">new</span> GridPane();
|
||||
|
||||
<span class="ST1">pb</span>.prefWidthProperty().bind(stage.widthProperty());
|
||||
|
||||
Label infoLabel = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">If you split a file named tmp into 3 smaller files,</span><span class="literal">\n</span><span class="string"> the three smaller files are temp.txt.1, temp.txt.2, and temp.txt.3. </span><span class="string">"</span>);
|
||||
Label chooseFile = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Choose a file to split: </span><span class="string">"</span>);
|
||||
Button openFilePicker = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Choose...</span><span class="string">"</span>);
|
||||
Label splitCountLabel = <span class="literal">new</span> Label(<span class="string">"</span><span class="string">Enter the amount of files to split into: </span><span class="string">"</span>);
|
||||
TextField splitCount = <span class="literal">new</span> TextField();
|
||||
Button run = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Start</span><span class="string">"</span>);
|
||||
textFieldGridPane.add(chooseFile, <span class="number">0</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.add(openFilePicker, <span class="number">1</span>, <span class="number">0</span>);
|
||||
textFieldGridPane.add(splitCountLabel, <span class="number">0</span>, <span class="number">1</span>);
|
||||
textFieldGridPane.add(splitCount, <span class="number">1</span>, <span class="number">1</span>);
|
||||
secondaryBoarderPane.<span class="ST3">setAlignment</span>(run, Pos.<span class="ST1">CENTER</span>);
|
||||
|
||||
primaryBorderPane.setTop(infoLabel);
|
||||
primaryBorderPane.setCenter(textFieldGridPane);
|
||||
|
||||
secondaryBoarderPane.setBottom(run);
|
||||
secondaryBoarderPane.setTop(<span class="ST1">p</span><span class="ST1">b</span>);
|
||||
|
||||
primaryBorderPane.setBottom(secondaryBoarderPane);
|
||||
|
||||
openFilePicker.setOnAction(e -> {
|
||||
<span class="ST1">file</span> = <span class="ST2">fileChooser</span>.showOpenDialog(openFilePicker.getScene().getWindow());
|
||||
});
|
||||
|
||||
run.setOnAction(e -> {
|
||||
<span class="literal">if</span> (<span class="ST1">file</span> == <span class="literal">null</span>) {
|
||||
e.consume();
|
||||
}
|
||||
<span class="ST3">splitFile</span>(<span class="ST1">f</span><span class="ST1">ile</span>, Integer.<span class="ST3">parseInt</span>(splitCount.getText()));
|
||||
});
|
||||
|
||||
Scene scene = <span class="literal">new</span> Scene(primaryBorderPane);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">splitFile</span>(File fileToSplit, <span class="literal">int</span> splitCount) {
|
||||
<span class="literal">int</span> outputFileSize = (<span class="literal">int</span>) fileToSplit.length() / splitCount;
|
||||
System.<span class="ST1">out</span>.println(<span class="string">"</span><span class="string">output file size will be: </span><span class="string">"</span> + outputFileSize);
|
||||
<span class="literal">if</span> (outputFileSize < <span class="number">0</span>) {
|
||||
<span class="ST1">alert</span>.setTitle(<span class="string">"</span><span class="string">Output files too large</span><span class="string">"</span>);
|
||||
<span class="ST1">alert</span>.setHeaderText(<span class="string">"</span><span class="string">Output files too large</span><span class="string">"</span>);
|
||||
<span class="ST1">alert</span>.setContentText(<span class="string">"</span><span class="string">Please increase the amount of files to split!</span><span class="string">"</span>);
|
||||
|
||||
<span class="ST1">alert</span>.showAndWait();
|
||||
<span class="literal">return</span>;
|
||||
}
|
||||
|
||||
<span class="literal">double</span> progress = <span class="number">0</span>;
|
||||
String outputPath = fileToSplit.getParent();
|
||||
<span class="comment">// Open the original file</span>
|
||||
<span class="literal">try</span> (FileInputStream dataIn = <span class="literal">new</span> FileInputStream(fileToSplit)) {
|
||||
System.<span class="ST1">out</span>.println(<span class="string">"</span><span class="string">Opening the source file!</span><span class="string">"</span>);
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < splitCount; ++i) {
|
||||
progress = (i * <span class="number">100</span>) / splitCount;
|
||||
System.<span class="ST1">out</span>.println(progress);
|
||||
<span class="ST1">pb</span>.setProgress(progress);
|
||||
dataIn.mark(outputFileSize * (i + <span class="number">1</span>));
|
||||
<span class="literal">try</span> (FileOutputStream dataOut = <span class="literal">new</span> FileOutputStream(outputPath + <span class="string">"</span><span class="string">/</span><span class="string">"</span> + fileToSplit.getName() + <span class="string">"</span><span class="string">.</span><span class="string">"</span> + (i + <span class="number">1</span>))) {
|
||||
dataOut.write(dataIn.readNBytes(outputFileSize), <span class="number">0</span>, outputFileSize);
|
||||
System.<span class="ST1">out</span>.println(<span class="string">"</span><span class="string">Writing to </span><span class="string">"</span> + outputPath + <span class="string">"</span><span class="string">/</span><span class="string">"</span> + fileToSplit.getName() + <span class="string">"</span><span class="string">.</span><span class="string">"</span> + (i + <span class="number">1</span>));
|
||||
}
|
||||
}
|
||||
|
||||
} <span class="literal">catch</span> (IOException ex) {
|
||||
System.<span class="ST1">out</span>.println(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args)
|
||||
{
|
||||
<span class="ST3">launch</span>();
|
||||
}
|
||||
}
|
||||
<span class="comment">/*</span>
|
||||
|
||||
<span class="comment"> */</span>
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -119,7 +119,43 @@ is divided into following sections:
|
||||
<property name="module.name" value=""/>
|
||||
</target>
|
||||
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property,-init-modules-supported" name="-do-init">
|
||||
<property name="platform.java" value="${java.home}/bin/java"/>
|
||||
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
|
||||
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
|
||||
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
|
||||
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
|
||||
<condition property="platform.javac" value="${platform.home}/bin/javac">
|
||||
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
|
||||
</condition>
|
||||
<property name="platform.javac" value="${platform.javac.tmp}"/>
|
||||
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
|
||||
<condition property="platform.java" value="${platform.home}/bin/java">
|
||||
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
|
||||
</condition>
|
||||
<property name="platform.java" value="${platform.java.tmp}"/>
|
||||
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
|
||||
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
|
||||
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
|
||||
</condition>
|
||||
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
|
||||
<condition property="platform.invalid" value="true">
|
||||
<or>
|
||||
<contains string="${platform.javac}" substring="$${platforms."/>
|
||||
<contains string="${platform.java}" substring="$${platforms."/>
|
||||
<contains string="${platform.javadoc}" substring="$${platforms."/>
|
||||
</or>
|
||||
</condition>
|
||||
<fail unless="platform.home">Must set platform.home</fail>
|
||||
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
|
||||
<fail unless="platform.java">Must set platform.java</fail>
|
||||
<fail unless="platform.javac">Must set platform.javac</fail>
|
||||
<fail if="platform.invalid">
|
||||
The J2SE Platform is not correctly set up.
|
||||
Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
|
||||
Either open the project in the IDE and setup the Platform with the same name or add it manually.
|
||||
For example like this:
|
||||
ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
|
||||
or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used)
|
||||
</fail>
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="splashscreen.available">
|
||||
<and>
|
||||
@ -242,20 +278,6 @@ is divided into following sections:
|
||||
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
|
||||
<isset property="profile.available"/>
|
||||
</condition>
|
||||
<condition else="false" property="jdkBug6558476">
|
||||
<and>
|
||||
<matches pattern="1\.[56]" string="${java.specification.version}"/>
|
||||
<not>
|
||||
<os family="unix"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition else="false" property="javac.fork">
|
||||
<or>
|
||||
<istrue value="${jdkBug6558476}"/>
|
||||
<istrue value="${javac.external.vm}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<property name="jar.index" value="false"/>
|
||||
<property name="jar.index.metainf" value="${jar.index}"/>
|
||||
<property name="copylibs.rebase" value="true"/>
|
||||
@ -343,7 +365,7 @@ is divided into following sections:
|
||||
</path>
|
||||
</resourcecount>
|
||||
</condition>
|
||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||
<src>
|
||||
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
||||
<include name="*"/>
|
||||
@ -394,7 +416,7 @@ is divided into following sections:
|
||||
<property location="${build.dir}/empty" name="empty.dir"/>
|
||||
<mkdir dir="${empty.dir}"/>
|
||||
<mkdir dir="@{apgeneratedsrcdir}"/>
|
||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||
<src>
|
||||
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
||||
<include name="*"/>
|
||||
@ -436,7 +458,7 @@ is divided into following sections:
|
||||
<sequential>
|
||||
<property location="${build.dir}/empty" name="empty.dir"/>
|
||||
<mkdir dir="${empty.dir}"/>
|
||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
|
||||
<src>
|
||||
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
||||
<include name="*"/>
|
||||
@ -515,7 +537,7 @@ is divided into following sections:
|
||||
<element name="customizePrototype" optional="true"/>
|
||||
<sequential>
|
||||
<property name="junit.forkmode" value="perTest"/>
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
@ -543,7 +565,7 @@ is divided into following sections:
|
||||
<element name="customizePrototype" optional="true"/>
|
||||
<sequential>
|
||||
<property name="junit.forkmode" value="perTest"/>
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
@ -619,7 +641,7 @@ is divided into following sections:
|
||||
</fileset>
|
||||
</union>
|
||||
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
||||
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="MP5-Binary-Files_CalebFontenot" testname="TestNG tests" workingDir="${work.dir}">
|
||||
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="MP5-Binary-Files_CalebFontenot" testname="TestNG tests" workingDir="${work.dir}">
|
||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||
<propertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
@ -850,6 +872,9 @@ is divided into following sections:
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<bootclasspath>
|
||||
<path path="${platform.bootcp}"/>
|
||||
</bootclasspath>
|
||||
</nbjpdastart>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
@ -899,7 +924,7 @@ is divided into following sections:
|
||||
<attribute default="jvm" name="jvm"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" module="@{modulename}">
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}" module="@{modulename}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
@ -933,7 +958,7 @@ is divided into following sections:
|
||||
<attribute default="jvm" name="jvm"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
@ -965,7 +990,7 @@ is divided into following sections:
|
||||
<attribute default="jvm" name="jvm"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
|
||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
|
||||
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
|
||||
@ -1199,7 +1224,7 @@ is divided into following sections:
|
||||
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
|
||||
<echo level="info">To run this application from the command line without Ant, try:</echo>
|
||||
<property location="${dist.jar}" name="dist.jar.resolved"/>
|
||||
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
|
||||
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
|
||||
</target>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
|
||||
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
|
||||
@ -1301,8 +1326,8 @@ is divided into following sections:
|
||||
<isset property="main.class.available"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="platform.jlink" value="${jdk.home}/bin/jlink"/>
|
||||
<property name="jlink.systemmodules.internal" value="${jdk.home}/jmods"/>
|
||||
<property name="platform.jlink" value="${platform.home}/bin/jlink"/>
|
||||
<property name="jlink.systemmodules.internal" value="${platform.home}/jmods"/>
|
||||
<exec executable="${platform.jlink}">
|
||||
<arg value="--module-path"/>
|
||||
<arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.jar}"/>
|
||||
@ -1495,16 +1520,19 @@ is divided into following sections:
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output">
|
||||
<arg value="-version"/>
|
||||
</exec>
|
||||
<condition else="" property="bug5101868workaround" value="*.java">
|
||||
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
|
||||
<matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
|
||||
</condition>
|
||||
<condition else="" property="javadoc.html5.cmd.line.arg" value="-html5">
|
||||
<and>
|
||||
<isset property="javadoc.html5"/>
|
||||
<available file="${jdk.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
|
||||
<available file="${platform.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
|
||||
</and>
|
||||
</condition>
|
||||
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
|
||||
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
|
||||
<classpath>
|
||||
<path path="${javac.classpath}"/>
|
||||
</classpath>
|
||||
|
@ -1,8 +1,8 @@
|
||||
build.xml.data.CRC32=a0844a83
|
||||
build.xml.data.CRC32=5b3e797d
|
||||
build.xml.script.CRC32=dee8d968
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.108.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=a0844a83
|
||||
nbproject/build-impl.xml.script.CRC32=025ed557
|
||||
nbproject/build-impl.xml.data.CRC32=5b3e797d
|
||||
nbproject/build-impl.xml.script.CRC32=7cb0beee
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48
|
||||
|
@ -49,7 +49,7 @@ javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.modulepath=\
|
||||
${libs.JavaFX20.classpath}
|
||||
${libs.JavaFX_20.classpath}
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
@ -101,7 +101,7 @@ manifest.custom.permissions=
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
platform.active=Graal_JDK_20
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}:\
|
||||
@ -109,7 +109,7 @@ run.classpath=\
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=-XX:+UnlockExperimentalVMOptions -XX:+EagerJVMCI -XX:+EnableJVMCI -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary
|
||||
run.jvmargs=--module-path=/usr/lib --add-modules javafx.controls -XX:+UnlockExperimentalVMOptions -XX:+EagerJVMCI -XX:+EnableJVMCI -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary
|
||||
run.modulepath=\
|
||||
${javac.modulepath}
|
||||
run.test.classpath=\
|
||||
|
@ -4,6 +4,7 @@
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>MP5-Binary-Files_CalebFontenot</name>
|
||||
<explicit-platform explicit-source-supported="true"/>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
|
@ -10,10 +10,16 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
@ -28,12 +34,11 @@ import javafx.stage.Stage;
|
||||
*/
|
||||
public class CombineFilesFX extends Application {
|
||||
|
||||
static List<File> files = null;
|
||||
static ArrayList<File> files = new ArrayList<File>();
|
||||
final FileChooser fileChooser = new FileChooser();
|
||||
|
||||
@Override
|
||||
public void start(final Stage stage) throws Exception
|
||||
{
|
||||
public void start(final Stage stage) throws Exception {
|
||||
fileChooser.setTitle("Open File to Split...");
|
||||
BorderPane primaryBorderPane = new BorderPane();
|
||||
GridPane textFieldGridPane = new GridPane();
|
||||
@ -51,7 +56,30 @@ public class CombineFilesFX extends Application {
|
||||
primaryBorderPane.setBottom(run);
|
||||
|
||||
openFilePicker.setOnAction(e -> {
|
||||
files = fileChooser.showOpenMultipleDialog(openFilePicker.getScene().getWindow());
|
||||
// When we initially get the files from the file chooser, it returns an unsortable list. Because of this, we need to create a new List with its data.
|
||||
files.addAll(fileChooser.showOpenMultipleDialog(openFilePicker.getScene().getWindow()));
|
||||
// The file picker appears to return files in a random order, so we need to sort them by file name.
|
||||
Collections.sort(files, new Comparator<File>() {
|
||||
public int compare(File o1, File o2) {
|
||||
return extractInt(o1.getName()) - extractInt(o2.getName());
|
||||
}
|
||||
|
||||
String findMatch(String s) {
|
||||
Pattern findNum = Pattern.compile("\\d+$");
|
||||
Matcher match = findNum.matcher(s);
|
||||
while (match.find()) {
|
||||
return match.group();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
int extractInt(String s) {
|
||||
String num = findMatch(s);
|
||||
System.out.println(num);
|
||||
// return 0 if no digits found
|
||||
return num.isEmpty() ? 0 : Integer.parseInt(num);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
run.setOnAction(e -> {
|
||||
@ -66,33 +94,37 @@ public class CombineFilesFX extends Application {
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void combineFiles(List<File> filesToCombine)
|
||||
{
|
||||
public static void combineFiles(List<File> filesToCombine) {
|
||||
String outputPath = filesToCombine.get(0).getParent();
|
||||
try (FileOutputStream dataOut = new FileOutputStream(outputPath + "/" + "reconstructed_" +filesToCombine.get(0).getName().substring( 0, (filesToCombine.get(0).getName().length() - 2)))) {
|
||||
System.out.println("Writing to " + outputPath + "/" + "reconstructed_" +filesToCombine.get(0).getName().substring( 0, ( filesToCombine.get(0).getName().length() - 2)));
|
||||
try (FileOutputStream dataOut = new FileOutputStream(outputPath + "/" + "reconstructed_" + filesToCombine.get(0).getName().substring(0, (filesToCombine.get(0).getName().length() - 2)))) {
|
||||
System.out.println("Writing to " + outputPath + "/" + "reconstructed_" + filesToCombine.get(0).getName().substring(0, (filesToCombine.get(0).getName().length() - 2)));
|
||||
for (File file : filesToCombine) {
|
||||
try (FileInputStream dataIn = new FileInputStream(file)) {
|
||||
System.out.println("Opening the source file!");
|
||||
byte[] buffer = new byte[4096]; // You can adjust the buffer size as needed
|
||||
System.out.println("Opening the source file " + file.getName() + "!");
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead = -1;
|
||||
|
||||
int bytesRead;
|
||||
while ((bytesRead = dataIn.read(buffer)) != -1) {
|
||||
dataOut.write(buffer, 0, bytesRead);
|
||||
while ((bytesRead = dataIn.read(buffer)) != -1) {
|
||||
dataOut.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
Alert alert = new Alert(AlertType.INFORMATION);
|
||||
alert.setTitle("Success!");
|
||||
alert.setContentText("Successfully combined the files!");
|
||||
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
*/
|
||||
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.mp5.files_calebfontenot;
|
||||
|
||||
import static com.calebfontenot.mp5.files_calebfontenot.SplitFilesFX.alert;
|
||||
import static com.calebfontenot.mp5.files_calebfontenot.SplitFilesFX.file;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class HexEditorFX extends Application {
|
||||
|
||||
final FileChooser fileChooser = new FileChooser();
|
||||
static File file = null;
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
Label label = new Label("Open a file...");
|
||||
Button openFileButton = new Button("Choose...");
|
||||
TextArea editorWindow = new TextArea();
|
||||
Button saveFileButton = new Button("Save");
|
||||
|
||||
editorWindow.setWrapText(true);
|
||||
|
||||
BorderPane bp = new BorderPane();
|
||||
GridPane openFileGridPane = new GridPane();
|
||||
|
||||
openFileGridPane.add(label, 0, 0);
|
||||
openFileGridPane.add(openFileButton, 1, 0);
|
||||
|
||||
bp.setTop(openFileGridPane);
|
||||
bp.setCenter(editorWindow);
|
||||
bp.setBottom(saveFileButton);
|
||||
bp.setAlignment(saveFileButton, Pos.CENTER);
|
||||
|
||||
openFileButton.setOnAction(e -> {
|
||||
file = fileChooser.showOpenDialog(openFileButton.getScene().getWindow());
|
||||
byte[] data = null;
|
||||
System.out.println("Getting data from fileand encoding it as hex...");
|
||||
try (FileInputStream dataIn = new FileInputStream(file)) {
|
||||
data = dataIn.readAllBytes();
|
||||
} catch (FileNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
String dataString = encodeHexString(data);
|
||||
editorWindow.setText(dataString);
|
||||
});
|
||||
|
||||
saveFileButton.setOnAction(e -> {
|
||||
if (file == null) {
|
||||
alert.setTitle("No file selected!");
|
||||
alert.setHeaderText("No file selected!");
|
||||
alert.setContentText("You have to open a file first, silly!");
|
||||
alert.showAndWait();
|
||||
}
|
||||
System.out.println("Re-encoding hex back into a byte array...");
|
||||
|
||||
try (FileOutputStream dataOut = new FileOutputStream(file)) {
|
||||
byte[] bytesToSave = decodeHexString(editorWindow.getText());
|
||||
dataOut.write(bytesToSave);
|
||||
} catch (FileNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
alert.setTitle("Invalid Hex!");
|
||||
alert.setContentText("Invalid hex entered into the text box, unable to save.");
|
||||
alert.showAndWait();
|
||||
}
|
||||
alert.setTitle("Save successful!");
|
||||
alert.setContentText("File saved successfully.");
|
||||
alert.showAndWait();
|
||||
});
|
||||
|
||||
Scene scene = new Scene(bp);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
|
||||
}
|
||||
|
||||
private int toDigit(char hexChar) {
|
||||
int digit = Character.digit(hexChar, 16);
|
||||
if (digit == -1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid Hexadecimal Character: " + hexChar);
|
||||
}
|
||||
return digit;
|
||||
}
|
||||
|
||||
public byte hexToByte(String hexString) {
|
||||
int firstDigit = toDigit(hexString.charAt(0));
|
||||
int secondDigit = toDigit(hexString.charAt(1));
|
||||
return (byte) ((firstDigit << 4) + secondDigit);
|
||||
}
|
||||
|
||||
public byte[] decodeHexString(String hexString) {
|
||||
if (hexString.length() % 2 == 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid hexadecimal String supplied.");
|
||||
}
|
||||
byte[] bytes = new byte[hexString.length() / 2];
|
||||
for (int i = 0; i < hexString.length(); i += 2) {
|
||||
bytes[i / 2] = hexToByte(hexString.substring(i, i + 2));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public String byteToHex(byte num) {
|
||||
char[] hexDigits = new char[2];
|
||||
hexDigits[0] = Character.forDigit((num >> 4) & 0xF, 16);
|
||||
hexDigits[1] = Character.forDigit((num & 0xF), 16);
|
||||
return new String(hexDigits);
|
||||
}
|
||||
|
||||
public String encodeHexString(byte[] byteArray) {
|
||||
StringBuffer hexStringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
hexStringBuffer.append(byteToHex(byteArray[i]));
|
||||
}
|
||||
return hexStringBuffer.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
@ -12,8 +12,10 @@ import java.io.IOException;
|
||||
import javafx.application.Application;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
@ -27,12 +29,17 @@ import javafx.stage.Stage;
|
||||
public class SplitFilesFX extends Application {
|
||||
static File file = null;
|
||||
final FileChooser fileChooser = new FileChooser();
|
||||
static ProgressBar pb = new ProgressBar();
|
||||
static Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
@Override
|
||||
public void start(final Stage stage) throws Exception
|
||||
{
|
||||
fileChooser.setTitle("Open File to Split...");
|
||||
BorderPane primaryBorderPane = new BorderPane();
|
||||
BorderPane secondaryBoarderPane = new BorderPane();
|
||||
GridPane textFieldGridPane = new GridPane();
|
||||
|
||||
pb.prefWidthProperty().bind(stage.widthProperty());
|
||||
|
||||
Label infoLabel = new Label("If you split a file named tmp into 3 smaller files,\n the three smaller files are temp.txt.1, temp.txt.2, and temp.txt.3. ");
|
||||
Label chooseFile = new Label("Choose a file to split: ");
|
||||
@ -44,11 +51,15 @@ public class SplitFilesFX extends Application {
|
||||
textFieldGridPane.add(openFilePicker, 1, 0);
|
||||
textFieldGridPane.add(splitCountLabel, 0, 1);
|
||||
textFieldGridPane.add(splitCount, 1, 1);
|
||||
primaryBorderPane.setAlignment(run, Pos.CENTER);
|
||||
secondaryBoarderPane.setAlignment(run, Pos.CENTER);
|
||||
|
||||
primaryBorderPane.setTop(infoLabel);
|
||||
primaryBorderPane.setCenter(textFieldGridPane);
|
||||
primaryBorderPane.setBottom(run);
|
||||
|
||||
secondaryBoarderPane.setBottom(run);
|
||||
secondaryBoarderPane.setTop(pb);
|
||||
|
||||
primaryBorderPane.setBottom(secondaryBoarderPane);
|
||||
|
||||
openFilePicker.setOnAction(e -> {
|
||||
file = fileChooser.showOpenDialog(openFilePicker.getScene().getWindow());
|
||||
@ -68,12 +79,26 @@ public class SplitFilesFX extends Application {
|
||||
|
||||
public static void splitFile(File fileToSplit, int splitCount) {
|
||||
int outputFileSize = (int) fileToSplit.length() / splitCount;
|
||||
System.out.println("output file size will be: " + outputFileSize);
|
||||
if (outputFileSize < 0) {
|
||||
alert.setTitle("Output files too large");
|
||||
alert.setHeaderText("Output files too large");
|
||||
alert.setContentText("Please increase the amount of files to split!");
|
||||
|
||||
alert.showAndWait();
|
||||
return;
|
||||
}
|
||||
|
||||
double progress = 0;
|
||||
String outputPath = fileToSplit.getParent();
|
||||
// Open the original file
|
||||
try (FileInputStream dataIn = new FileInputStream(fileToSplit)) {
|
||||
System.out.println("Opening the source file!");
|
||||
for (int i = 0; i < splitCount; ++i) {
|
||||
//dataIn.mark(outputFileSize * (i + 1));
|
||||
progress = (i * 100) / splitCount;
|
||||
System.out.println(progress);
|
||||
pb.setProgress(progress);
|
||||
dataIn.mark(outputFileSize * (i + 1));
|
||||
try (FileOutputStream dataOut = new FileOutputStream(outputPath + "/" + fileToSplit.getName() + "." + (i + 1))) {
|
||||
dataOut.write(dataIn.readNBytes(outputFileSize), 0, outputFileSize);
|
||||
System.out.println("Writing to " + outputPath + "/" + fileToSplit.getName() + "." + (i + 1));
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue
Block a user