Skip to content

Commit

Permalink
Merge pull request #3 from marlonrcfranco/develop
Browse files Browse the repository at this point in the history
release 0.1.2
  • Loading branch information
marlonrcfranco authored Sep 4, 2019
2 parents ed58d0b + 5ec169f commit 5fdb7d0
Show file tree
Hide file tree
Showing 32 changed files with 530 additions and 147 deletions.
54 changes: 10 additions & 44 deletions jcon.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand All @@ -9,53 +9,19 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../jcifs-1.3.19.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.4">
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-api-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/opentest4j-1.1.1.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-platform-commons-1.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-params-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-engine-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-platform-engine-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-api-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/opentest4j-1.1.1.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-platform-commons-1.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-params-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-jupiter-engine-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../lib/junit-platform-engine-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.28" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.28" level="project" />
<orderEntry type="library" name="Maven: com.hierynomus:smbj:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.60" level="project" />
<orderEntry type="library" name="Maven: net.engio:mbassador:1.3.0" level="project" />
<orderEntry type="library" name="Maven: com.hierynomus:asn-one:0.4.0" level="project" />
<orderEntry type="library" name="Maven: jcifs:jcifs:1.3.17" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.5.1" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.5.1" level="project" />
</component>
</module>
69 changes: 60 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
<groupId>groupId</groupId>
<artifactId>jcon</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>com.hierynomus</groupId>
<artifactId>smbj</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand All @@ -17,15 +39,44 @@
<target>9</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludes>META-INF/*.SF</excludes>
<excludes>META-INF/*.DSA</excludes>
<excludes>META-INF/*.RSA</excludes>
<excludes>META-INF/*.*</excludes>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>jcon</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.marlonrcfranco.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.hierynomus</groupId>
<artifactId>smbj</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>


</project>
7 changes: 6 additions & 1 deletion src/main/java/com/marlonrcfranco/IJcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public interface IJcon {

enum types {
FILESYSTEM,SMB1,SMB23,NFS
}

/**
* public String read(String IP, String filePath, String user, String pass)
*
Expand All @@ -23,6 +27,7 @@ public interface IJcon {
* @throws IOException
*/
public String read(String IP, String filePath, String user, String pass) throws IOException;
public byte[] readBytes(String IP, String filePath, String user, String pass) throws IOException;

/**
* public String write(String IP, String filePath, String user, String pass, String content)
Expand All @@ -43,6 +48,7 @@ public interface IJcon {
* @throws IOException
*/
public String write(String IP, String filePath, String user, String pass, String content) throws IOException;
public byte[] writeBytes(String IP, String filePath, String user, String pass, byte[] content) throws IOException;

/**
* public String copyFileTo(String sourceIP, String sourceFilePath, String destIP, String destFilePath, String user, String pass)
Expand All @@ -68,5 +74,4 @@ public interface IJcon {
*/
public String copyFileTo(String sourceIP, String sourceFilePath, String destIP, String destFilePath, String user, String pass) throws IOException;


}
72 changes: 72 additions & 0 deletions src/main/java/com/marlonrcfranco/Jcon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.marlonrcfranco;

import java.io.IOException;

public class Jcon {
private IJcon jcon;
private IJcon.types type;
private String response;

public Jcon(IJcon.types type) {
this.type = type;
try {
if (type == IJcon.types.FILESYSTEM) {
this.jcon = new JconFileSystem();
}
else if (type == IJcon.types.SMB1) {
this.jcon = new JconSMB1();
}
else if (type == IJcon.types.SMB23) {
this.jcon = new JconSMB23();
}
else if (type == IJcon.types.NFS) {
// Not implemented yet
}
} catch(Exception e) {
this.jcon = null;
}
}

public String read(String IP, String filePath, String user, String pass) throws Exception{
String path = "";
try {
path = filePath;
this.response = this.jcon.read(IP,path,user,pass);

String jjRows = "\""+this.response+"\"";
String jjStatus = this.response.contains("Erro")? "500": "200";

String json = "{\"status\":\""+jjStatus+"\",\"rows\":["+jjRows+"]}";
return json;

} catch (IOException e) {
return "{\"status\":\"500\",\"message\":\"Ocorreu um erro na execução.\",\"rows\":[]}";
}
}

public byte[] readBytes(String IP, String filePath, String user, String pass) throws IOException {
return this.jcon.readBytes(IP,filePath,user,pass);
}

public String write(String IP, String filePath, String user, String pass, String content) throws Exception{
String path = "";
try {
path = filePath;
this.response = this.jcon.write(IP,path,user,pass,content);

String jjRows = "\""+this.response+"\"";
String jjStatus = this.response.contains("Erro")? "500": "200";

String json = "{\"status\":\""+jjStatus+"\",\"rows\":["+jjRows+"]}";
return json;

} catch (IOException e) {
return "{\"status\":\"500\",\"message\":\"Ocorreu um erro na execução.\",\"rows\":[]}";
}
}

public byte[] writeBytes(String IP, String filePath, String user, String pass, byte[] content) throws IOException {
return this.jcon.writeBytes(IP,filePath,user,pass,content);
}

}
35 changes: 22 additions & 13 deletions src/main/java/com/marlonrcfranco/JconFileSystem.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.marlonrcfranco;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;

public class JconFileSystem implements IJcon{

Expand All @@ -21,16 +18,21 @@ public String read(String filePath) throws IOException{

@Override
public String read(String IP, String filePath, String user, String pass) throws IOException {
String output="";
return new String(readBytes(IP,filePath,user,pass));
}

@Override
public byte[] readBytes(String IP, String filePath, String user, String pass) throws IOException {
byte[] output = "".getBytes(); //2^17
filePath = filePath.replace("\\", "/");
FileInputStream file = null;
try {
file = new FileInputStream(filePath);
output=new String(file.readAllBytes());
output = Util.toByteArray(file);
} catch (FileNotFoundException e) {
output= "Erro: Não foi possível localizar o arquivo \""+filePath+"\"";
output= ("Erro: Não foi possível localizar o arquivo \""+filePath+"\"").getBytes();
} catch (IOException e) {
output= "Erro: Não foi possível ler o arquivo \""+filePath+"\"";
output= ("Erro: Não foi possível ler o arquivo \""+filePath+"\"").getBytes();
}
finally {
if (file != null) file.close();
Expand All @@ -44,17 +46,22 @@ public String write(String filePath,String content) throws IOException{

@Override
public String write(String IP, String filePath, String user, String pass, String content) throws IOException{
String output="";
return new String(writeBytes(IP,filePath,user,pass,content.getBytes()));
}

@Override
public byte[] writeBytes(String IP, String filePath, String user, String pass, byte[] content) throws IOException {
byte[] output="".getBytes();
filePath = filePath.replace("\\", "/");
FileOutputStream file = null;
try {
file = new FileOutputStream(filePath);
file.write(content.getBytes());
output="Escrita concluída com sucesso";
file.write(content);
output=("Escrita concluída com sucesso").getBytes();
} catch (FileNotFoundException e) {
output= "Erro: Não foi possível localizar o caminho \""+filePath+"\"";
output=("Erro: Não foi possível localizar o caminho \""+filePath+"\"").getBytes();
} catch (IOException e) {
output= "Erro: Não foi possível ler o arquivo \""+filePath+"\"";
output=("Erro: Não foi possível ler o arquivo \""+filePath+"\"").getBytes();
}
finally {
if (file != null) file.close();
Expand Down Expand Up @@ -102,4 +109,6 @@ public String copyFileTo(String sourceIP, String sourceFilePath, String destIP,
return output;
}



}
Loading

0 comments on commit 5fdb7d0

Please sign in to comment.