mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Work on JingleFileTransfer
This commit is contained in:
parent
c0e5fcf737
commit
186dfd224e
10 changed files with 171 additions and 34 deletions
|
@ -39,10 +39,10 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
|
|||
private final HashElement hash;
|
||||
private final String mediaType;
|
||||
private final String name;
|
||||
private final int size;
|
||||
private final long size;
|
||||
private final Range range;
|
||||
|
||||
public JingleFileTransferChildElement(Date date, String desc, HashElement hash, String mediaType, String name, int size, Range range) {
|
||||
public JingleFileTransferChildElement(Date date, String desc, HashElement hash, String mediaType, String name, long size, Range range) {
|
||||
this.date = date;
|
||||
this.desc = desc;
|
||||
this.hash = hash;
|
||||
|
@ -72,7 +72,7 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
|
|||
return name;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
|
|||
sb.optElement(ELEM_NAME, name);
|
||||
sb.optElement(range);
|
||||
if (size > 0) {
|
||||
sb.element(ELEM_SIZE, Integer.toString(size));
|
||||
sb.element(ELEM_SIZE, Long.toString(size));
|
||||
}
|
||||
sb.optElement(hash);
|
||||
sb.closeElement(this);
|
||||
|
@ -113,7 +113,7 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
|
|||
private HashElement hash;
|
||||
private String mediaType;
|
||||
private String name;
|
||||
private int size;
|
||||
private long size;
|
||||
private Range range;
|
||||
|
||||
private Builder() {
|
||||
|
@ -152,7 +152,7 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setSize(int size) {
|
||||
public Builder setSize(long size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft.element;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
|
@ -27,6 +28,9 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildEleme
|
|||
*/
|
||||
public class JingleFileTransferElement extends JingleContentDescriptionElement {
|
||||
|
||||
public JingleFileTransferElement(JingleContentDescriptionChildElement payload) {
|
||||
this(Collections.singletonList(payload));
|
||||
}
|
||||
|
||||
public JingleFileTransferElement(List<JingleContentDescriptionChildElement> payloads) {
|
||||
super(payloads);
|
||||
|
|
|
@ -1,38 +1,21 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public class JingleFileOffer extends JingleFileTransfer {
|
||||
public abstract class JingleFileOffer<D extends JingleFileTransferFile> extends JingleFileTransfer {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleFileOffer.class.getName());
|
||||
protected D jingleFile;
|
||||
|
||||
private File file;
|
||||
|
||||
public JingleFileOffer(File file) {
|
||||
public JingleFileOffer(D fileTransferFile) {
|
||||
super();
|
||||
this.file = file;
|
||||
this.jingleFile = fileTransferFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportReady(BytestreamSession bytestreamSession) {
|
||||
OutputStream outputStream;
|
||||
|
||||
try {
|
||||
outputStream = bytestreamSession.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Error retrieving outputStream: " + e, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public JingleFileTransferElement getElement() {
|
||||
return new JingleFileTransferElement(jingleFile.getElement());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public class JingleFileRequest extends JingleFileTransfer {
|
||||
|
||||
@Override
|
||||
public JingleFileTransferElement getElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportReady(BytestreamSession bytestreamSession) {
|
||||
|
||||
|
|
|
@ -11,8 +11,4 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
|
|||
public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5";
|
||||
public static final String NAMESPACE = NAMESPACE_V5;
|
||||
|
||||
@Override
|
||||
public JingleFileTransferElement getElement() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
*/
|
||||
public abstract class JingleFileTransferFile {
|
||||
|
||||
public JingleFileTransferFile() {
|
||||
|
||||
}
|
||||
|
||||
public JingleFileTransferChildElement getElement() {
|
||||
JingleFileTransferChildElement.Builder builder = JingleFileTransferChildElement.getBuilder();
|
||||
builder.setDate(getDate());
|
||||
builder.setSize(getSize());
|
||||
builder.setName(getName());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public abstract Date getDate();
|
||||
|
||||
public abstract long getSize();
|
||||
|
||||
public abstract String getName();
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
*/
|
||||
public class JingleIncomingFileOffer extends JingleFileOffer<RemoteFile> {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleIncomingFileOffer.class.getName());
|
||||
|
||||
public JingleIncomingFileOffer(JingleFileTransferChildElement offer) {
|
||||
super(new RemoteFile(offer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportReady(BytestreamSession bytestreamSession) {
|
||||
OutputStream outputStream;
|
||||
try {
|
||||
outputStream = bytestreamSession.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Cannot get OutputStream from BytestreamSession: " + e, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
*/
|
||||
public class JingleOutgoingFileOffer extends JingleFileOffer<LocalFile> {
|
||||
|
||||
public JingleOutgoingFileOffer(File file) {
|
||||
super(new LocalFile(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportReady(BytestreamSession bytestreamSession) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
*/
|
||||
public class LocalFile extends JingleFileTransferFile {
|
||||
|
||||
private File file;
|
||||
|
||||
public LocalFile(File file) {
|
||||
super();
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDate() {
|
||||
return new Date(file.lastModified());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
String path = file.getAbsolutePath();
|
||||
return path.substring(path.lastIndexOf(File.pathSeparatorChar)+1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
*/
|
||||
public class RemoteFile extends JingleFileTransferFile {
|
||||
|
||||
private JingleFileTransferChildElement file;
|
||||
|
||||
public RemoteFile(JingleFileTransferChildElement file) {
|
||||
super();
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDate() {
|
||||
return file.getDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return file.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return file.getName();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue