Ejemplo n.º 1
0
  public edu.cmu.cs.dennisc.java.util.zip.DataSource getOriginalProgramTypeDataSource() {
    java.io.File file = edu.cmu.cs.dennisc.java.net.UriUtilities.getFile(getUri());
    org.lgna.project.Project project = getProject();
    if (file != null) {
      java.util.zip.ZipFile zipFile;
      byte[] buffer = null;
      try {
        zipFile = new java.util.zip.ZipFile(file);
        java.io.InputStream typeStream =
            zipFile.getInputStream(
                new java.util.zip.ZipEntry(
                    org.lgna.project.io.IoUtilities.ORIGINAL_PROGRAM_TYPE_ENTRY_NAME));

        if (typeStream != null) {
          buffer = new byte[typeStream.available()];
          org.apache.axis.utils.IOUtils.readFully(typeStream, buffer);
        } else {
          java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
          edu.cmu.cs.dennisc.xml.XMLUtilities.write(project.getProgramType().encode(), os);
          buffer = os.toByteArray();
        }
        zipFile.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (buffer != null) {
        final byte[] originalType = buffer;
        return new edu.cmu.cs.dennisc.java.util.zip.DataSource() {
          @Override
          public String getName() {
            return org.lgna.project.io.IoUtilities.ORIGINAL_PROGRAM_TYPE_ENTRY_NAME;
          }

          @Override
          public void write(java.io.OutputStream os) throws IOException {
            os.write(originalType);
          }
        };
      }
    }
    return null;
  }
Ejemplo n.º 2
0
  public edu.cmu.cs.dennisc.java.util.zip.DataSource getOriginalVersionDataSource() {
    java.io.File file = edu.cmu.cs.dennisc.java.net.UriUtilities.getFile(getUri());
    org.lgna.project.Project project = getProject();
    if (file != null) {
      java.util.zip.ZipFile zipFile;
      byte[] buffer = null;
      try {
        zipFile = new java.util.zip.ZipFile(file);
        java.io.InputStream typeStream =
            zipFile.getInputStream(
                new java.util.zip.ZipEntry(
                    org.lgna.project.io.IoUtilities.ORIGINAL_VERSION_ENTRY_NAME));

        if (typeStream != null) {
          buffer = new byte[typeStream.available()];
          org.apache.axis.utils.IOUtils.readFully(typeStream, buffer);
        } else {
          Version version = org.lgna.project.ProjectVersion.getCurrentVersion();
          buffer = version.toString().getBytes();
        }
        zipFile.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (buffer != null) {
        final byte[] originalVersion = buffer;
        return new edu.cmu.cs.dennisc.java.util.zip.DataSource() {
          @Override
          public String getName() {
            return org.lgna.project.io.IoUtilities.ORIGINAL_VERSION_ENTRY_NAME;
          }

          @Override
          public void write(java.io.OutputStream os) throws IOException {
            os.write(originalVersion);
          }
        };
      }
    }
    return null;
  }