Esempio n. 1
0
 public SVNProperties asMap() throws SVNException {
   SVNProperties result = new SVNProperties();
   if (isEmpty()) {
     return result;
   }
   ByteArrayOutputStream nameOS = new ByteArrayOutputStream();
   InputStream is = SVNFileUtil.openFileForReading(getFile(), SVNLogType.WC);
   try {
     while (readProperty('K', is, nameOS)) {
       String name = new String(nameOS.toByteArray(), "UTF-8");
       nameOS.reset();
       readProperty('V', is, nameOS);
       byte[] value = nameOS.toByteArray();
       result.put(name, value);
       nameOS.reset();
     }
   } catch (IOException e) {
     SVNErrorMessage err =
         SVNErrorMessage.create(
             SVNErrorCode.IO_ERROR,
             "Cannot read properties file ''{0}'': {1}",
             new Object[] {getFile(), e.getLocalizedMessage()});
     SVNErrorManager.error(err, e, SVNLogType.WC);
   } finally {
     SVNFileUtil.closeFile(is);
   }
   return result;
 }
Esempio n. 2
0
 public OutputStream getPropertyValue(String name, OutputStream os) throws SVNException {
   if (isEmpty()) {
     return null;
   }
   ByteArrayOutputStream nameOS = new ByteArrayOutputStream();
   InputStream is = SVNFileUtil.openFileForReading(getFile(), SVNLogType.WC);
   try {
     while (readProperty('K', is, nameOS)) {
       String currentName = new String(nameOS.toByteArray(), "UTF-8");
       nameOS.reset();
       if (currentName.equals(name)) {
         readProperty('V', is, os);
         return os;
       }
       readProperty('V', is, null);
     }
   } catch (IOException e) {
     SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e.getLocalizedMessage());
     SVNErrorManager.error(err, e, SVNLogType.WC);
   } finally {
     SVNFileUtil.closeFile(is);
   }
   return null;
 }
Esempio n. 3
0
  /** @noinspection ResultOfMethodCallIgnored */
  private static boolean copyProperties(
      InputStream is, OutputStream os, String name, InputStream value, int length)
      throws SVNException {
    // read names, till name is met, then insert value or skip this
    // property.
    int propCount = 0;
    try {
      if (is != null) {
        int l = 0;
        while ((l = readLength(is, 'K')) > 0) {
          byte[] nameBytes = new byte[l];

          SVNFileUtil.readIntoBuffer(is, nameBytes, 0, nameBytes.length);
          is.read();
          if (name.equals(new String(nameBytes, "UTF-8"))) {
            // skip property, will be appended.
            readProperty('V', is, null);
            continue;
          }
          // save name
          writeProperty(os, 'K', nameBytes);
          l = readLength(is, 'V');
          writeProperty(os, 'V', is, l);
          is.read();
          propCount++;
        }
      }
      if (value != null && length >= 0) {
        byte[] nameBytes = name.getBytes("UTF-8");
        writeProperty(os, 'K', nameBytes);
        writeProperty(os, 'V', value, length);
        propCount++;
      }
      if (propCount > 0) {
        os.write(new byte[] {'E', 'N', 'D', '\n'});
      }
    } catch (IOException e) {
      SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e.getLocalizedMessage());
      SVNErrorManager.error(err, e, SVNLogType.WC);
    }
    return propCount > 0;
  }
Esempio n. 4
0
 public Collection properties(Collection target) throws SVNException {
   target = target == null ? new TreeSet() : target;
   if (isEmpty()) {
     return target;
   }
   ByteArrayOutputStream nameOS = new ByteArrayOutputStream();
   InputStream is = SVNFileUtil.openFileForReading(getFile(), SVNLogType.WC);
   try {
     while (readProperty('K', is, nameOS)) {
       target.add(new String(nameOS.toByteArray(), "UTF-8"));
       nameOS.reset();
       readProperty('V', is, null);
     }
   } catch (IOException e) {
     SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e.getLocalizedMessage());
     SVNErrorManager.error(err, e, SVNLogType.WC);
   } finally {
     SVNFileUtil.closeFile(is);
   }
   return target;
 }