Да, как сказал Даниил, с помощью переопределения __cmp__
вы можете получить это:
class Comparable(object):
def __init__(self, below_class, above_class):
self.above_class = above_class
self.below_class = below_class
def __cmp__(self, other):
if isinstance(other, self.below_class):
return 1
if isinstance(other, self.above_class):
return -1
return 0
class Paper(Comparable):
pass
class Rock(Comparable):
pass
class Scissors(Comparable):
pass
scissors = Scissors(Paper, Rock)
paper = Paper(Rock, Scissors)
rock = Rock(Scissors, Paper)
# True
print paper > rock
print scissors > paper
print rock > scissors
# False
print paper < rock
print scissors < paper
print rock < scissors
Документация о том, как это работает, доступна здесь: https: //docs.python .org / 2.6 / ссылка / datamodel.html # объекта. CMP
public byte[] download(URL url) throws IOException {
URLConnection uc = url.openConnection();
int len = uc.getContentLength();
InputStream is = new BufferedInputStream(uc.getInputStream());
try {
byte[] data = new byte[len];
int offset = 0;
while (offset < len) {
int read = is.read(data, offset, data.length - offset);
if (read < 0) {
break;
}
offset += read;
}
if (offset < len) {
throw new IOException(
String.format("Read %d bytes; expected %d", offset, len));
}
return data;
} finally {
is.close();
}
}
Править: Очищенный код.
Проверьте URL и классы URLConnection. Вот некоторая документация: http://www.exampledepot.com/egs/java.net/Post.html
Если намерение состоит в том, чтобы выполнить другой ресурс, в то время как Ваш сервлет выполняется с передачей управления к другому ресурсу, можно попытаться использовать, включают (запрос, ответ).
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/url of other resource");
if (dispatcher != null)
dispatcher.include(request, response);
}
Можно поместить это на сервлет, и результат другого ресурса включен в сервлет.
Править: Так как Вы надеетесь получать файл тогда это решение работы для этого также.