Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	bin/jobexftp
  • Loading branch information
sbamamoto committed Feb 21, 2016
2 parents 67c2aad + a0bacc4 commit ff55e0d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 58 deletions.
99 changes: 60 additions & 39 deletions src/main/java/com/lhf/obexftplib/etc/Utility.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Created on Oct 21, 2010
* This file is part of JObexFTP 2.0, and it contains parts of OBEX4J.
* Created on Oct 21, 2010 This file is part of JObexFTP 2.0, and it contains
* parts of OBEX4J.
*
* JObexFTP is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* JObexFTP is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* JObexFTP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* JObexFTP is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JObexFTP. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Lesser General Public License
* along with JObexFTP. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.lhf.obexftplib.etc;
Expand Down Expand Up @@ -94,9 +94,10 @@ public static String readStandardInput() {
// }
// return CommPortIdentifier.getPortIdentifier(connPortPath);
// }

/**
* Checks for the combination looking from end to begining, in the whole array
* Checks for the combination looking from end to begining, in the whole
* array
*
* @param b
* @return true if found, false otherwise
*/
Expand Down Expand Up @@ -195,7 +196,7 @@ public static byte[] intToBytes(final int integer, final int bLength) {
*/
public static int bytesToInt(final byte[] bytes) {
int result = 0;
if (bytes == null ) {
if (bytes == null) {
return 0;
}
for (int i = 0; i < bytes.length; i++) {
Expand Down Expand Up @@ -284,8 +285,8 @@ public static String byteToHexString(final byte inbyte) {
* convert the list of ByteArray to a single byte array
*
* @param list List whose elements are instances of ByteArray class
* @return single byte array result in the concatenation of all the
* elements of the given list
* @return single byte array result in the concatenation of all the elements
* of the given list
*/
static byte[] byteArrayListToBytes(final ArrayList list) {
if (list == null) {
Expand Down Expand Up @@ -397,6 +398,7 @@ public static GetResponse bytesToGetResponse(final byte[] incomingData) {

/**
* Builds a byte array for names in obex format
*
* @param name
* @return
* @see Utility#bytesToName(byte[])
Expand Down Expand Up @@ -439,7 +441,9 @@ public static byte[] prepareMoveByteArray(String oldPath, String newPath) throws
}

/**
* Replaces all slashes '\' for backslashes '/', removes the last backslash and remove the drive letter 'a:'
* Replaces all slashes '\' for backslashes '/', removes the last backslash
* and remove the drive letter 'a:'
*
* @param path the path to be prepared
* @return the prepared path
* @see Utility#removeLastSlash(java.lang.String)
Expand All @@ -454,6 +458,7 @@ public static String preparePath(String path) {

/**
* Removes the last slash ('/') from any string.
*
* @param path
* @return
*/
Expand All @@ -466,6 +471,7 @@ public static String removeLastSlash(String path) {

/**
* Compares the two absolute pathes and build an realtive path to get in the
*
* @param absolutePath The absolute path to some file or folder
* @param actualFolder The absolute path of the origin folder
* @return The realtive path from actualFolder to absolutePath
Expand Down Expand Up @@ -495,6 +501,7 @@ public static String getRelativePath(final String absolutePath, final String act

/**
* gets the last folder form a path.
*
* @param path an absolute or relative path
* @return the last folder
*/
Expand All @@ -506,6 +513,7 @@ public static String getLastFolder(String path) {

/**
* gets the last folder form a path.
*
* @param path an absolute or relative path
* @return the last folder
*/
Expand All @@ -519,8 +527,10 @@ public static String removeLastFolder(String path) {
}

/**
* This function is used when the Path is known, but there is no OBEXFolder referenciating it.
* So it makes easier to user OBEXFolder to movein or create folders.
* This function is used when the Path is known, but there is no OBEXFolder
* referenciating it. So it makes easier to user OBEXFolder to movein or
* create folders.
*
* @param absolutePath an absolutpath, starting with a:/ or /
* @return the last level OBEXFolder of the path specified.
*/
Expand All @@ -539,48 +549,55 @@ public static OBEXFolder createSimbolicFolderTree(String absolutePath) {
}
/**
* DateFormat for getTime
*
* @see Utility#getTime(java.util.Date)
*/
private static final DateFormat OBEX_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");

/**
* Builds a string in the SimpleDateFormat of yyyyMMdd'T'HHmmss
*
* @param time the time
* @return String representation of the SimpleDateFormat of yyyyMMdd'T'HHmmss in the specified time
* @return String representation of the SimpleDateFormat of
* yyyyMMdd'T'HHmmss in the specified time
*/
public static String getTime(final Date time) {
return OBEX_DATE_FORMAT.format(time);
}

/**
* Helper to check response values
*
* @param res
* @return true if is Response.CONTINUE Response.SUCCESS Response.CREATED, false otherwise
* @return true if is Response.CONTINUE Response.SUCCESS Response.CREATED,
* false otherwise
*/
public static boolean threatResponse(final Response res) {
boolean b = false;
switch (res.getType() & 0x7F) {
case Response.CONTINUE:
b = true;
break;
case Response.SUCCESS:
b = true;
break;
case Response.BADREQUEST:
b = false;
break;
case Response.CREATED:
b = true;
break;
default:
b = false;
if (res != null) {
switch (res.getType() & 0x7F) {
case Response.CONTINUE:
b = true;
break;
case Response.SUCCESS:
b = true;
break;
case Response.BADREQUEST:
b = false;
break;
case Response.CREATED:
b = true;
break;
default:
b = false;
}
}

return b;
}

/**
* Creates byte array to set user, group and others permissions.
*
* @param read if read granted
* @param write if write granted
* @param delete if delete granted
Expand Down Expand Up @@ -611,6 +628,7 @@ public static byte[] buildPerm(final boolean read, final boolean write, final bo

/**
* Builds the name from bytes used by OBEX
*
* @param name the name in obex format
* @return the name in human readable
* @see Utility#nameToBytes(java.lang.String)
Expand All @@ -627,6 +645,7 @@ public static String bytesToName(final byte[] name) {

/**
* Creates byte array to set user, group and others permissions.
*
* @param userPerm the string containing the permited operations.
* @param type the type to user, group or others.
* @return the array
Expand Down Expand Up @@ -696,7 +715,9 @@ public static StringBuilder listingFormat(StringBuilder builder, String filename
}

/**
* Gets a long representation of a yyyyMMdd'T'HHmmss time representated String
* Gets a long representation of a yyyyMMdd'T'HHmmss time representated
* String
*
* @param value
* @return
* @see Utility#getTime(java.util.Date)
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/com/lhf/obexftplib/fs/OBEXObject.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* Last updated in 21/Out/2010
*
* This file is part of JObexFTP.
* This file is part of JObexFTP.
*
* JObexFTP is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* JObexFTP is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* JObexFTP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* JObexFTP is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JObexFTP. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Lesser General Public License
* along with JObexFTP. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.lhf.obexftplib.fs;
Expand All @@ -30,7 +30,9 @@
import java.util.Iterator;

/**
* Abstract class containing common attributes and behavior of OBEXFile and OBEXFolder.
* Abstract class containing common attributes and behavior of OBEXFile and
* OBEXFolder.
*
* @author Ricardo Guilherme Schmidt <[email protected]>
*/
public abstract class OBEXObject {
Expand Down Expand Up @@ -62,8 +64,10 @@ public OBEXObject(final OBEXFolder parentFolder, final String name) {
}

public void addResponse(final Response res) {
for (Iterator<Header> it = res.getHeaders(); it.hasNext();) {
threatHeader(it.next());
if (res != null) {
for (Iterator<Header> it = res.getHeaders(); it.hasNext();) {
threatHeader(it.next());
}
}
}

Expand Down Expand Up @@ -156,7 +160,9 @@ public String getGroupPerm() {
}

/**
* TODO: Find the correct groupperm byte (its not 0x38) and add it at OBEXFile#getHeaderSet().
* TODO: Find the correct groupperm byte (its not 0x38) and add it at
* OBEXFile#getHeaderSet().
*
* @param groupPerm the groupPerm to set
*/
public void setGroupPerm(final boolean read, final boolean write, final boolean delete) {
Expand Down Expand Up @@ -188,6 +194,7 @@ public final void reset() {

/**
* Resets and sets the content of this object.
*
* @param contents
* @throws IOException
*/
Expand Down Expand Up @@ -221,6 +228,7 @@ public void setTime(final Date time) {

/**
* The time to set in yyyyMMdd'T'HHmmss time representated String
*
* @param value
*/
public void setTime(final String value) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/lhf/obexftplib/io/OBEXClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ public boolean writeFile(final OBEXFile file) throws IOException, SerialPortExce
res = put(req);
req = new PutRequest();

} while ((res.getType() & 0x7F) == Response.CONTINUE);
} while (res != null && (res.getType() & 0x7F) == Response.CONTINUE);
is.close();
file.setInputStream(null);
return (res.getType() & 0x7F) == Response.SUCCESS;
return res != null && (res.getType() & 0x7F) == Response.SUCCESS;
}
}

Expand Down Expand Up @@ -464,7 +464,7 @@ private GetResponse[] getAll(GetRequest request) throws IOException, SerialPortE
do {
arrayList.add(response = get(request));
request = new GetRequest();
} while ((response.getType() & 0x7F) == Response.CONTINUE);
} while (response!=null && (response.getType() & 0x7F) == Response.CONTINUE);

GetResponse[] responses = new GetResponse[arrayList.size()];
responses = arrayList.toArray(responses);
Expand Down Expand Up @@ -553,7 +553,7 @@ public void DataEvent(final byte[] event) {
public void update(final int mode, final boolean changed) {
if (mode != ATConnection.MODE_DATA && !changed) {
try {
logger.log(Level.WARNING, "Datamode to close unexpectedly");
logger.log(Level.WARNING, "Datamode to close unexpectedly mode was:"+ mode + " change was "+changed);
try {
// abort();
disconnect();
Expand Down

0 comments on commit ff55e0d

Please sign in to comment.