Исправления и дополнения.

This commit is contained in:
Victor 2013-06-01 16:46:20 +03:00
parent 6e5b0d66e6
commit 1bcc8bdcb1
12 changed files with 86 additions and 94 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/build/ /build/
/dist/ /dist/
/nbproject/private/

View File

@ -51,8 +51,7 @@
-init-macrodef-junit: defines macro for junit execution -init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging -init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution -init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest) -do-jar: JAR building
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project run: execution of project
-javadoc-build: Javadoc generation -javadoc-build: Javadoc generation
test-report: JUnit report generation test-report: JUnit report generation

View File

@ -54,6 +54,7 @@ is divided into following sections:
<property file="nbproject/project.properties"/> <property file="nbproject/project.properties"/>
</target> </target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init"> <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
<property name="platform.java" value="${java.home}/bin/java"/>
<available file="${manifest.file}" property="manifest.available"/> <available file="${manifest.file}" property="manifest.available"/>
<condition property="splashscreen.available"> <condition property="splashscreen.available">
<and> <and>
@ -71,10 +72,11 @@ is divided into following sections:
</not> </not>
</and> </and>
</condition> </condition>
<condition property="manifest.available+main.class"> <condition property="profile.available">
<and> <and>
<isset property="manifest.available"/> <isset property="javac.profile"/>
<isset property="main.class.available"/> <length length="0" string="${javac.profile}" when="greater"/>
<matches pattern="1\.[89](\..*)?" string="${javac.source}"/>
</and> </and>
</condition> </condition>
<condition property="do.archive"> <condition property="do.archive">
@ -91,12 +93,6 @@ is divided into following sections:
</not> </not>
</and> </and>
</condition> </condition>
<condition property="manifest.available+main.class+mkdist.available">
<and>
<istrue value="${manifest.available+main.class}"/>
<isset property="do.mkdist"/>
</and>
</condition>
<condition property="do.archive+manifest.available"> <condition property="do.archive+manifest.available">
<and> <and>
<isset property="manifest.available"/> <isset property="manifest.available"/>
@ -115,24 +111,12 @@ is divided into following sections:
<istrue value="${do.archive}"/> <istrue value="${do.archive}"/>
</and> </and>
</condition> </condition>
<condition property="do.archive+manifest.available+main.class"> <condition property="do.archive+profile.available">
<and> <and>
<istrue value="${manifest.available+main.class}"/> <isset property="profile.available"/>
<istrue value="${do.archive}"/> <istrue value="${do.archive}"/>
</and> </and>
</condition> </condition>
<condition property="manifest.available-mkdist.available">
<or>
<istrue value="${manifest.available}"/>
<isset property="do.mkdist"/>
</or>
</condition>
<condition property="manifest.available+main.class-mkdist.available">
<or>
<istrue value="${manifest.available+main.class}"/>
<isset property="do.mkdist"/>
</or>
</condition>
<condition property="have.tests"> <condition property="have.tests">
<or> <or>
<available file="${test.src.dir}"/> <available file="${test.src.dir}"/>
@ -188,6 +172,9 @@ is divided into following sections:
<condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'"> <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
<length length="0" string="${endorsed.classpath}" when="greater"/> <length length="0" string="${endorsed.classpath}" when="greater"/>
</condition> </condition>
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
<isset property="profile.available"/>
</condition>
<condition else="false" property="jdkBug6558476"> <condition else="false" property="jdkBug6558476">
<and> <and>
<matches pattern="1\.[56]" string="${java.specification.version}"/> <matches pattern="1\.[56]" string="${java.specification.version}"/>
@ -275,6 +262,7 @@ is divided into following sections:
<path path="@{classpath}"/> <path path="@{classpath}"/>
</classpath> </classpath>
<compilerarg line="${endorsed.classpath.cmd.line.arg}"/> <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
<compilerarg line="${javac.profile.cmd.line.arg}"/>
<compilerarg line="${javac.compilerargs}"/> <compilerarg line="${javac.compilerargs}"/>
<compilerarg value="-processorpath"/> <compilerarg value="-processorpath"/>
<compilerarg path="@{processorpath}:${empty.dir}"/> <compilerarg path="@{processorpath}:${empty.dir}"/>
@ -314,6 +302,7 @@ is divided into following sections:
<path path="@{classpath}"/> <path path="@{classpath}"/>
</classpath> </classpath>
<compilerarg line="${endorsed.classpath.cmd.line.arg}"/> <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
<compilerarg line="${javac.profile.cmd.line.arg}"/>
<compilerarg line="${javac.compilerargs}"/> <compilerarg line="${javac.compilerargs}"/>
<customize/> <customize/>
</javac> </javac>
@ -446,7 +435,7 @@ is divided into following sections:
</fileset> </fileset>
</union> </union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/> <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="SocketFileTransfer" testname="TestNG tests" workingDir="${work.dir}"> <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="SocketFileTransfer" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/> <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset> <propertyset>
<propertyref prefix="test-sys-prop."/> <propertyref prefix="test-sys-prop."/>
@ -966,41 +955,25 @@ is divided into following sections:
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. --> <!-- You can override this target in the ../build.xml file. -->
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available-mkdist.available"> <target depends="init" if="do.archive" name="-do-jar-create-manifest" unless="manifest.available">
<j2seproject1:jar/>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class-mkdist.available">
<j2seproject1:jar manifest="${manifest.file}"/>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
<j2seproject1:jar manifest="${manifest.file}">
<j2seproject1:manifest>
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
</j2seproject1:manifest>
</j2seproject1:jar>
<echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<pathconvert property="run.classpath.with.dist.jar">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
</pathconvert>
<echo level="info">java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
</target>
<target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/> <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<touch file="${tmp.manifest.file}" verbose="false"/> <touch file="${tmp.manifest.file}" verbose="false"/>
</target> </target>
<target depends="init" if="do.archive+manifest.available" name="-do-jar-with-libraries-copy-manifest"> <target depends="init" if="do.archive+manifest.available" name="-do-jar-copy-manifest">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/> <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<copy file="${manifest.file}" tofile="${tmp.manifest.file}"/> <copy file="${manifest.file}" tofile="${tmp.manifest.file}"/>
</target> </target>
<target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+main.class.available" name="-do-jar-with-libraries-set-main"> <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass">
<manifest file="${tmp.manifest.file}" mode="update"> <manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/> <attribute name="Main-Class" value="${main.class}"/>
</manifest> </manifest>
</target> </target>
<target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-with-libraries-set-splashscreen"> <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+profile.available" name="-do-jar-set-profile">
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Profile" value="${javac.profile}"/>
</manifest>
</target>
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-set-splashscreen">
<basename file="${application.splash}" property="splashscreen.basename"/> <basename file="${application.splash}" property="splashscreen.basename"/>
<mkdir dir="${build.classes.dir}/META-INF"/> <mkdir dir="${build.classes.dir}/META-INF"/>
<copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/> <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
@ -1008,23 +981,41 @@ is divided into following sections:
<attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/> <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
</manifest> </manifest>
</target> </target>
<target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen" if="do.mkdist" name="-do-jar-with-libraries-pack"> <target depends="init,-init-macrodef-copylibs,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" if="do.mkdist" name="-do-jar-copylibs">
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/> <j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
<echo level="info">To run this application from the command line without Ant, try:</echo> <echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/> <property location="${dist.jar}" name="dist.jar.resolved"/>
<echo level="info">java -jar "${dist.jar.resolved}"</echo> <echo level="info">java -jar "${dist.jar.resolved}"</echo>
</target> </target>
<target depends="-do-jar-with-libraries-pack" if="do.archive" name="-do-jar-with-libraries-delete-manifest"> <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" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<pathconvert property="run.classpath.with.dist.jar">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
</pathconvert>
<condition else="" property="jar.usage.message" value="To run this application from the command line without Ant, try:${line.separator}${platform.java} -cp ${run.classpath.with.dist.jar} ${main.class}">
<isset property="main.class.available"/>
</condition>
<condition else="debug" property="jar.usage.level" value="info">
<isset property="main.class.available"/>
</condition>
<echo level="${jar.usage.level}" message="${jar.usage.message}"/>
</target>
<target depends="-do-jar-copylibs" if="do.archive" name="-do-jar-delete-manifest">
<delete> <delete>
<fileset file="${tmp.manifest.file}"/> <fileset file="${tmp.manifest.file}"/>
</delete> </delete>
</target> </target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen,-do-jar-with-libraries-pack,-do-jar-with-libraries-delete-manifest" name="-do-jar-with-libraries"/> <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,-do-jar-jar,-do-jar-delete-manifest" name="-do-jar-without-libraries"/>
<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,-do-jar-copylibs,-do-jar-delete-manifest" name="-do-jar-with-libraries"/>
<target name="-post-jar"> <target name="-post-jar">
<!-- Empty placeholder for easier customization. --> <!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. --> <!-- You can override this target in the ../build.xml file. -->
</target> </target>
<target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/> <target depends="init,compile,-pre-jar,-do-jar-without-libraries,-do-jar-with-libraries,-post-jar" name="-do-jar"/>
<target depends="init,compile,-pre-jar,-do-jar,-post-jar" description="Build JAR." name="jar"/>
<!-- <!--
================= =================
EXECUTION SECTION EXECUTION SECTION

View File

@ -1,8 +1,8 @@
build.xml.data.CRC32=b5a554e2 build.xml.data.CRC32=b5a554e2
build.xml.script.CRC32=5cee8796 build.xml.script.CRC32=464901e2
build.xml.stylesheet.CRC32=28e38971@1.56.0.46 build.xml.stylesheet.CRC32=8064a381@1.63.0.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # 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. # 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=b5a554e2 nbproject/build-impl.xml.data.CRC32=b5a554e2
nbproject/build-impl.xml.script.CRC32=1f769548 nbproject/build-impl.xml.script.CRC32=85fc706a
nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.0.46 nbproject/build-impl.xml.stylesheet.CRC32=4e931b40@1.63.0.46

View File

@ -11,8 +11,8 @@ import java.net.Socket;
*/ */
public class Client { public class Client {
private Socket clientSocket; private final Socket clientSocket;
private OperationManager manager; private final OperationManager manager;
public Client(String host) throws IOException { public Client(String host) throws IOException {
clientSocket = new Socket(host, Config.getPort()); clientSocket = new Socket(host, Config.getPort());

View File

@ -1,6 +1,3 @@
/*
* aNNiMON 2013
*/
package com.annimon.socketfiletransfer; package com.annimon.socketfiletransfer;
import com.annimon.socketfiletransfer.util.Config; import com.annimon.socketfiletransfer.util.Config;
@ -36,13 +33,20 @@ public class FileOperation implements Operation {
FileOutputStream fout = null; FileOutputStream fout = null;
try { try {
String name = dis.readUTF(); String name = dis.readUTF();
long length = dis.readLong();
System.out.println("Filename: " + name); System.out.println("Filename: " + name);
System.out.println("Size: " + (length / 1024) + "kb");
fout = new FileOutputStream(Config.getTransferDir() + name); fout = new FileOutputStream(Config.getTransferDir() + name);
byte[] buffer = new byte[BUFFER_SIZE];
int count; for (long i = 0; i < length; i++) {
while ((count = dis.read(buffer, 0, BUFFER_SIZE)) != -1) { byte read = dis.readByte();
fout.write(buffer, 0, count); fout.write(read);
} }
/*byte[] buffer = new byte[BUFFER_SIZE];
int count;
while ((count = dis.read(buffer, 0, BUFFER_SIZE)) > 0) {
fout.write(buffer, 0, count);
}*/
fout.flush(); fout.flush();
fout.close(); fout.close();
} catch (IOException ex) { } catch (IOException ex) {
@ -65,6 +69,8 @@ public class FileOperation implements Operation {
String name = file.getName(); String name = file.getName();
dos.writeUTF(name); dos.writeUTF(name);
dos.writeLong(file.length());
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
int count; int count;

View File

@ -1,6 +1,3 @@
/*
* aNNiMON 2013
*/
package com.annimon.socketfiletransfer; package com.annimon.socketfiletransfer;
import com.annimon.socketfiletransfer.util.ExceptionHandler; import com.annimon.socketfiletransfer.util.ExceptionHandler;
@ -15,7 +12,8 @@ import javax.swing.JOptionPane;
public class Main { public class Main {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if (args[0].equalsIgnoreCase("server")) { if (args.length == 0) {
// Çàïóñê ñåðâåðà.
try { try {
Server server = new Server(); Server server = new Server();
server.listenClients(); server.listenClients();
@ -25,14 +23,20 @@ public class Main {
return; return;
} }
// Çàïóñê êëèåíòà.
String host = "127.0.0.1"; String host = "127.0.0.1";
if (args.length >= 3) {
host = args[2];
} else {
host = getHostIp(host);
}
try { try {
Client client = new Client(getHostIp(host)); Client client = new Client(host);
if (args[1].equalsIgnoreCase("file")) { if (args[0].equalsIgnoreCase("file")) {
String filePath = args[2]; String filePath = args[1];
client.getManager().sendFile( new File(filePath) ); client.getManager().sendFile( new File(filePath) );
} else if (args[1].equalsIgnoreCase("message")) { } else if (args[0].equalsIgnoreCase("message")) {
String message = args[2]; String message = args[1];
client.getManager().sendMessage(message); client.getManager().sendMessage(message);
} }
client.close(); client.close();

View File

@ -1,6 +1,3 @@
/*
* aNNiMON 2013
*/
package com.annimon.socketfiletransfer; package com.annimon.socketfiletransfer;
/** /**

View File

@ -1,6 +1,3 @@
/*
* aNNiMON 2013
*/
package com.annimon.socketfiletransfer; package com.annimon.socketfiletransfer;
import java.io.DataInputStream; import java.io.DataInputStream;

View File

@ -3,6 +3,7 @@ package com.annimon.socketfiletransfer;
import com.annimon.socketfiletransfer.util.Config; import com.annimon.socketfiletransfer.util.Config;
import com.annimon.socketfiletransfer.util.ExceptionHandler; import com.annimon.socketfiletransfer.util.ExceptionHandler;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
@ -12,10 +13,12 @@ import java.net.Socket;
*/ */
public class Server { public class Server {
private ServerSocket serverSocket; private final ServerSocket serverSocket;
public Server() throws IOException { public Server() throws IOException {
serverSocket = new ServerSocket(Config.getPort()); serverSocket = new ServerSocket(Config.getPort());
System.out.print("Start server ");
System.out.println(InetAddress.getLocalHost().getHostAddress());
} }
public void listenClients() { public void listenClients() {

View File

@ -9,7 +9,7 @@ import java.net.Socket;
*/ */
public class TransferServer implements Runnable { public class TransferServer implements Runnable {
private OperationListener listener; private final OperationListener listener;
public TransferServer(Socket client) { public TransferServer(Socket client) {
listener = new OperationListener(); listener = new OperationListener();

View File

@ -9,15 +9,9 @@ import java.io.File;
public class Config { public class Config {
private static final String private static final String
TYPE = "TYPE",
PORT = "PORT", PORT = "PORT",
TRANSFER_DIR = "TRANSFER_DIR"; TRANSFER_DIR = "TRANSFER_DIR";
public static boolean isServer() {
String type = Configuration.getInstance().getProperty(TYPE);
return (type.equalsIgnoreCase("server"));
}
public static int getPort() { public static int getPort() {
String value = Configuration.getInstance().getProperty(PORT); String value = Configuration.getInstance().getProperty(PORT);
try { try {
@ -31,8 +25,8 @@ public class Config {
public static String getTransferDir() { public static String getTransferDir() {
String path = Configuration.getInstance().getProperty(TRANSFER_DIR); String path = Configuration.getInstance().getProperty(TRANSFER_DIR);
path = path.trim(); path = path.trim();
if (!path.endsWith(File.pathSeparator)) { if (!path.endsWith(File.separator)) {
path = path + File.pathSeparator; path = path + File.separator;
} }
return path; return path;
} }