public InputStream checkout(long version) throws IOException, IllegalArgumentException { if (version <= 0) { throw new IllegalArgumentException("Version must be greater than 0."); } URL url = buildCommand(m_url, COMMAND_CHECKOUT, version); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() == HttpServletResponse.SC_NOT_FOUND) { throw new IllegalArgumentException("Requested version not found in remote repository. (" + connection.getResponseMessage() + ")"); } if (connection.getResponseCode() != HttpServletResponse.SC_OK) { throw new IOException("Connection error: " + connection.getResponseMessage()); } return connection.getInputStream(); }
public boolean commit(InputStream data, long fromVersion) throws IOException, IllegalArgumentException { URL url = buildCommand(m_url, COMMAND_COMMIT, fromVersion); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", MIME_APPLICATION_OCTET_STREAM); OutputStream out = connection.getOutputStream(); copy(data, out); out.flush(); out.close(); return connection.getResponseCode() == HttpServletResponse.SC_OK; }
public SortedRangeSet getRange() throws IOException { URL url = buildCommand(m_url, COMMAND_QUERY, 0); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() == HttpServletResponse.SC_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = reader.readLine(); if (line == null) { throw new IOException("Repository not found: customer=" + m_customer + ", name=" + m_name); } String representation = line.substring(line.lastIndexOf(',')); reader.close(); return new SortedRangeSet(representation); } throw new IOException("Connection error: " + connection.getResponseMessage()); }