Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

update filter name rule for folder #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sl-objectstorage/.idea/*
*/.idea/*
bin/*
Binary file added sl-objectstorage/lib/commons-io-2.4.jar
Binary file not shown.
5 changes: 1 addition & 4 deletions sl-objectstorage/src/com/softlayer/objectstorage/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* other dealings in this Software without prior written authorization from
* SoftLayer Technologies, Inc.
*
* Portions Copyright � 2008-9 Rackspace US, Inc.
* Portions Copyright � 2008-9 Rackspace US, Inc.
*
*
* base client for making calls to objectstorage API
Expand Down Expand Up @@ -431,9 +431,6 @@ protected boolean isValidName(String name) {
if (length == 0 || length > 256) {
return false;
}
if (name.indexOf('/') != -1) {
return false;
}
return true;
}

Expand Down
46 changes: 40 additions & 6 deletions sl-objectstorage/src/com/softlayer/objectstorage/ObjectFile.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.softlayer.objectstorage;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.*;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -46,7 +42,7 @@
* other dealings in this Software without prior written authorization from
* SoftLayer Technologies, Inc.
*
* Portions Copyright � 2008-9 Rackspace US, Inc.
* Portions Copyright � 2008-9 Rackspace US, Inc.
*
* This represents a file object on the objectstorage server
*
Expand Down Expand Up @@ -182,6 +178,44 @@ public String uploadFile(String localFileLocation, Map<String, String> tags)

}

/**
* upload this file from a local file copy to the objectstorage server
*
* @param inputStream
* stream of input data from file
* @param tags
* Map of tags to attach to this file
* @return etag value of this upload
* @throws EncoderException
* @throws IOException
*/
public String uploadFile(InputStream inputStream, Map<String, String> tags)
throws EncoderException, IOException {
if (super.isValidName(this.name)) {
Hashtable<String, String> params = super.createAuthParams();
Iterator<Map.Entry<String, String>> it = tags.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pairs = (Map.Entry<String, String>) it
.next();
params.put(Client.X_OBJECT_META + pairs.getKey(),
pairs.getValue());
it.remove();
}

String uName = super.saferUrlEncode(this.containerName);
String fName = super.saferUrlEncode(this.name);
Representation representation = new InputRepresentation(inputStream, MediaType.ALL);
ClientResource client = super.put(params, representation,
super.storageurl + "/" + uName + "/" + fName);
this.headers = client.getResponseAttributes();
Form head = (Form) this.headers.get("org.restlet.http.headers");
return head.getFirstValue("Etag");
} else {
throw new EncoderException("invalid file name");
}

}

/**
* removes this file form the objectstorage server
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.softlayer.objectstorage.test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
Expand All @@ -9,6 +10,7 @@
import junit.framework.TestCase;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.restlet.data.Form;
Expand Down Expand Up @@ -111,6 +113,25 @@ public void testObjectFileCreate() throws IOException, EncoderException {
assertTrue(false);
}

@Test
public void testObjectFileCreateFromStream() throws IOException, EncoderException {
ObjectFile ofile = new ObjectFile("restletupload.txt",
"RestletContainer", baseUrl, user, password, true);
Map<String, String> tags = new HashMap<String, String>();
tags.put("testtag", "testvalue");
ofile.uploadFile(FileUtils.openInputStream(new File("restletupload.txt")), tags);
Container container = new Container("RestletContainer", baseUrl, user,
password, true);
List<ObjectFile> files = container.listObjectFiles();
for (ObjectFile file : files) {
if (file.getName().equalsIgnoreCase("restletupload.txt")) {

return;
}
}
assertTrue(false);
}

@Test
public void testGetMetaTag() throws IOException, EncoderException {
ObjectFile ofile = new ObjectFile("restletupload.txt",
Expand Down