Examples of BufferedWriter


Examples of java.io.BufferedWriter

    return finalKeyList.elements();
  }

  public void store(OutputStream out, String comments) throws IOException {
    BufferedWriter bw = null;
    try {
      bw = new BufferedWriter(new OutputStreamWriter(out, "8859_1"));

      bw.write("#" + new Date().toString());
      bw.newLine();
      String lastkeyPrefix = "";
      String key = null;
      String val = null;
 
      for (Enumeration e = keys(); e.hasMoreElements();) {
        key = (String) e.nextElement();
        val = (String) get(key);
        key = LabelFileEncodingHelper.saveConvert(key, true);
        val = LabelFileEncodingHelper.saveConvert(val, false);
 
        if (!lastkeyPrefix.equals(key.substring(0, key.indexOf(".") + 1))) {
          bw.newLine();
        }
 
        bw.write(key + "=" + val);
        lastkeyPrefix = key.substring(0, key.indexOf(".") + 1);
        bw.newLine();
      }
 
      bw.flush();
    } finally {
      if (bw != null) {
        try {
          bw.close();
        } catch (IOException e) {
        }       
      }
    }
  }
View Full Code Here

Examples of java.io.BufferedWriter

      }      
    }

    // stores labelfile
    FileOutputStream labelFileStream = null;
    BufferedWriter writer = null;
    try {
      if (isSortLabelFiles()) {
        Properties labelProperties = loadLabel(labelFile);
        labelProperties.setProperty(key, value);
        SortedProperties sortedProperties = new SortedProperties();
        sortedProperties.putAll(labelProperties);
        labelFileStream = new FileOutputStream(labelFile.getLocation().toString());
        sortedProperties.store(labelFileStream, null);
     
       
      } else {
        // append new label to existing file
        Properties labelProperties = loadLabel(labelFile);
        if (!labelProperties.containsKey(key)) {
          writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(labelFile.getLocation().toFile(), true), "8859_1"));
          if(labelProperties.entrySet().size()>0){
            writer.newLine();
          }         
          writer.write(LabelFileEncodingHelper.saveConvert(key, true));
          writer.write("=");
          writer.write(LabelFileEncodingHelper.saveConvert(value, false));         
          writer.flush();
       
        }
      }
      labelFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
    } catch (FileNotFoundException e) {
      Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Can't find propertyfile : " + labelFile.getLocation(), e));
    } catch (IOException e) {
      Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Can't write propertyfile : " + labelFile.getLocation(), e));
    } catch (CoreException e) {
      Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, "Can't find propertyfile : " + labelFile.getLocation(), e));
    }finally{
      if(labelFileStream!=null){
        try {
          labelFileStream.close();
        } catch (IOException e) {       
        }
      }
      if(writer!=null){
        try {
          writer.close();
        } catch (IOException e) {
        }
      }
     
    }
View Full Code Here

Examples of java.io.BufferedWriter

                                               Map<Content, String> contentEntries) throws IOException {
    boolean keepURLContentUnchanged = !offlineFurnitureLibrary
        && furnitureResourcesRemoteAbsoluteUrlBase == null
        && furnitureResourcesRemoteRelativeUrlBase == null;
    Set<String> existingEntryNames = new HashSet<String>();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "ISO-8859-1"));
    final String CATALOG_FILE_HEADER = "#\n# "
        + DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY + ".properties %tc\n"
        + "# Generated by Furniture Library Editor\n#\n";
    writer.write(String.format(CATALOG_FILE_HEADER, new Date()));
    writer.newLine();
    writeProperty(writer, DESCRIPTION, furnitureLibrary.getDescription());
    writeProperty(writer, VERSION, furnitureLibrary.getVersion());
    writeProperty(writer, LICENSE, furnitureLibrary.getLicense());
    writeProperty(writer, PROVIDER, furnitureLibrary.getProvider());
   
    int i = 1;
    for (CatalogPieceOfFurniture piece : furnitureLibrary.getFurniture()) {
      writer.newLine();
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.ID, i, piece.getId());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.NAME, i, piece.getName());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DESCRIPTION, i, piece.getDescription());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.CATEGORY, i, piece.getCategory().getName());
      Content pieceModel = piece.getModel();
      String contentBaseName;
      if (contentMatchingFurnitureName
          || !(pieceModel instanceof URLContent)
          || ((URLContent)pieceModel).getURL().getFile().toString().endsWith("model.obj")) {
        contentBaseName = piece.getName();
      } else {
        String file = ((URLContent)pieceModel).getURL().getFile();
        if (file.lastIndexOf('/') != -1) {
          file = file.substring(file.lastIndexOf('/') + 1);
        }
        if (file.lastIndexOf('.') != -1) {
          file = file.substring(0, file.lastIndexOf('.'));
        }
        contentBaseName = file;
      }
      String iconContentEntryName = getContentEntry(piece.getIcon(), contentBaseName + ".png",
          keepURLContentUnchanged, existingEntryNames);
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.ICON, i,
          getContentProperty(piece.getIcon(), iconContentEntryName, offlineFurnitureLibrary,
              furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase));
      if (iconContentEntryName != null) {
        contentEntries.put(piece.getIcon(), iconContentEntryName);
      }
      if (piece.getPlanIcon() != null) {
        String planIconContentEntryName = getContentEntry(piece.getPlanIcon(), contentBaseName + "PlanIcon.png",
            keepURLContentUnchanged, existingEntryNames);
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.PLAN_ICON, i,
            getContentProperty(piece.getPlanIcon(), planIconContentEntryName, offlineFurnitureLibrary,
                furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase));
        if (planIconContentEntryName != null) {
          contentEntries.put(piece.getPlanIcon(), planIconContentEntryName);
        }
      }
      boolean multipart = pieceModel instanceof ResourceURLContent
              && ((ResourceURLContent)pieceModel).isMultiPartResource()
          || !(pieceModel instanceof ResourceURLContent)
              && pieceModel instanceof URLContent
              && ((URLContent)pieceModel).isJAREntry();
      String modelContentEntryName;
      if (multipart) {
        String jarEntryName = ((URLContent)pieceModel).getJAREntryName();
        modelContentEntryName = getContentEntry(pieceModel,
            pieceModel instanceof TemporaryURLContent
                ? contentBaseName + "/" + jarEntryName
                : contentBaseName + "/" + jarEntryName.substring(jarEntryName.lastIndexOf('/') + 1)
            keepURLContentUnchanged, existingEntryNames);
      } else {
        modelContentEntryName = getContentEntry(pieceModel,
            contentBaseName + ".obj", keepURLContentUnchanged, existingEntryNames);
      }
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MODEL, i,
          getContentProperty(pieceModel, modelContentEntryName, offlineFurnitureLibrary,
              furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase));
      if (modelContentEntryName != null) {
        contentEntries.put(pieceModel, modelContentEntryName);
      }
      if (multipart) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MULTI_PART_MODEL, i, "true");
      }
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.WIDTH, i, piece.getWidth());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DEPTH, i, piece.getDepth());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.HEIGHT, i, piece.getHeight());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MOVABLE, i, piece.isMovable());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW, i, piece.isDoorOrWindow());
      if (piece.isDoorOrWindow()) {
        // Write properties specific to doors and windows
        DoorOrWindow doorOrWindow = (DoorOrWindow)piece;
        if (doorOrWindow.getWallThickness() != 1) {
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_WALL_THICKNESS, i,
              doorOrWindow.getWallThickness() * doorOrWindow.getDepth());
        }
        if (doorOrWindow.getWallDistance() != 0) {
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_WALL_DISTANCE, i,
              doorOrWindow.getWallDistance() * doorOrWindow.getDepth());
        }
        Sash [] sashes = doorOrWindow.getSashes();
        if (sashes.length > 0) {
          String sashXAxis = "";
          String sashYAxis = "";
          String sashWidth = "";
          String sashStartAngle = "";
          String sashEndAngle = "";
          for (int sashIndex = 0; sashIndex < sashes.length; sashIndex++) {
            if (sashIndex > 0) {
              sashXAxis += " ";
              sashYAxis += " ";
              sashWidth += " ";
              sashStartAngle += " ";
              sashEndAngle += " ";
            }
            sashXAxis += sashes [sashIndex].getXAxis() * doorOrWindow.getWidth();
            sashYAxis += sashes [sashIndex].getYAxis() * doorOrWindow.getDepth();
            sashWidth += sashes [sashIndex].getWidth() * doorOrWindow.getWidth();
            sashStartAngle += Math.round(Math.toDegrees(sashes [sashIndex].getStartAngle()) * 100) / 100;
            sashEndAngle += Math.round(Math.toDegrees(sashes [sashIndex].getEndAngle()) * 100) / 100;
          }         
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_X_AXIS, i, sashXAxis);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_Y_AXIS, i, sashYAxis);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_WIDTH, i, sashWidth);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_START_ANGLE, i, sashStartAngle);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DOOR_OR_WINDOW_SASH_END_ANGLE, i, sashEndAngle);
        }
      }
      if (piece instanceof Light) {
        // Write properties specific to lights
        Light light = (Light)piece;
        LightSource [] lightSources = light.getLightSources();
        if (lightSources.length > 0) {
          String lightSourceX = "";
          String lightSourceY = "";
          String lightSourceZ = "";
          String lightSourceColor = "";
          String lightSourceDiameter = null;
          for (int lightIndex = 0; lightIndex < lightSources.length; lightIndex++) {
            if (lightIndex > 0) {
              lightSourceX += " ";
              lightSourceY += " ";
              lightSourceZ += " ";
              lightSourceColor += " ";
              if (lightSourceDiameter != null) {
                lightSourceDiameter += " ";
              }
            }
            lightSourceX += lightSources [lightIndex].getX() * light.getWidth();
            lightSourceY += lightSources [lightIndex].getY() * light.getDepth();
            lightSourceZ += lightSources [lightIndex].getZ() * light.getHeight();
            lightSourceColor += "#" + Integer.toHexString(lightSources [lightIndex].getColor());
            if (lightSources [lightIndex].getDiameter() != null) {
              if (lightSourceDiameter == null) {
                lightSourceDiameter = "";
              }
              lightSourceDiameter += lightSources [lightIndex].getDiameter() * light.getWidth();
            }
          }         
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_X, i, lightSourceX);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_Y, i, lightSourceY);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_Z, i, lightSourceZ);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_COLOR, i, lightSourceColor);
          writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.LIGHT_SOURCE_DIAMETER, i, lightSourceDiameter);
        }
      }
      if (piece.getElevation() > 0) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.ELEVATION, i, piece.getElevation());
      }
      float [][] modelRotation = piece.getModelRotation();
      String modelRotationString =
          Math.round(modelRotation[0][0]) + " " + Math.round(modelRotation[0][1]) + " " + Math.round(modelRotation[0][2]) + " "
        + Math.round(modelRotation[1][0]) + " " + Math.round(modelRotation[1][1]) + " " + Math.round(modelRotation[1][2]) + " "
        + Math.round(modelRotation[2][0]) + " " + Math.round(modelRotation[2][1]) + " " + Math.round(modelRotation[2][2]);
      if (!"1 0 0 0 1 0 0 0 1".equals(modelRotationString)) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.MODEL_ROTATION, i, modelRotationString);
      }
      if (!piece.isResizable()) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.RESIZABLE, i, piece.isResizable());
      }
      if (!piece.isDeformable()) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DEFORMABLE, i, piece.isDeformable());
      }
      if (!piece.isTexturable()) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.TEXTURABLE, i, piece.isTexturable());
      }
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.PRICE, i, piece.getPrice());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.VALUE_ADDED_TAX_PERCENTAGE, i, piece.getValueAddedTaxPercentage());
      writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.CREATOR, i, piece.getCreator());
      i++;
    }
    writer.flush();
  }
View Full Code Here

Examples of java.io.BufferedWriter

   * with properties as defined as in <code>DefaultFurnitureCatalog</code>.
   */
  private void writeFurnitureLibraryLocalizedProperties(OutputStream output,
                                                        FurnitureLibrary furnitureLibrary,
                                                        String language) throws IOException {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "ISO-8859-1"));
    final String CATALOG_FILE_HEADER = "#\n# "
        + DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY + "_" + language + ".properties %tc\n"
        + "# Generated by Furniture Library Editor\n#\n";
    writer.write(String.format(CATALOG_FILE_HEADER, new Date()));
    int i = 1;
    for (CatalogPieceOfFurniture piece : furnitureLibrary.getFurniture()) {
      writer.newLine();
      Object pieceName = furnitureLibrary.getPieceOfFurnitureLocalizedData(
          piece, language, FurnitureLibrary.FURNITURE_NAME_PROPERTY);
      if (pieceName != null) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.NAME, i, pieceName);
      }
      Object pieceDescription = furnitureLibrary.getPieceOfFurnitureLocalizedData(
          piece, language, FurnitureLibrary.FURNITURE_DESCRIPTION_PROPERTY);
      if (pieceDescription != null) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.DESCRIPTION, i, pieceDescription);
      }
      Object categoryName = furnitureLibrary.getPieceOfFurnitureLocalizedData(
          piece, language, FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY);
      if (categoryName != null) {
        writeProperty(writer, DefaultFurnitureCatalog.PropertyKey.CATEGORY, i, categoryName);
      }
      i++;
    }
    writer.flush();
  }
View Full Code Here

Examples of java.io.BufferedWriter

        String dir = destDir + "/" + packageName.replace('.', '/');
        (new File(dir)).mkdirs();
        String fileName = dir + "/" + clazz.name() + ".html";
        String className = getClass(clazz);
        FileWriter out = new FileWriter(fileName);
        PrintWriter writer = new PrintWriter(new BufferedWriter(out));
        writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " +
                "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
        String language = "en";
        writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" " +
                "lang=\"" + language + "\" xml:lang=\"" + language + "\">");
View Full Code Here

Examples of java.io.BufferedWriter

                Matcher m = p.matcher(model);
                if (m.find()) {
                    String className = m.group().substring("class".length()).trim();
                    File classFile = new File(parentFile, className + ".java");
                    Writer o = new FileWriter(classFile, false);
                    PrintWriter writer = new PrintWriter(new BufferedWriter(o));
                    writer.write(model);
                    writer.close();
                    System.out.println("Generated " + classFile.getAbsolutePath());
                }
            }
View Full Code Here

Examples of java.io.BufferedWriter

    public ReaderInputStream(Reader reader) {
        chars = new char[Constants.IO_BUFFER_SIZE];
        this.reader = reader;
        out = new ByteArrayOutputStream(Constants.IO_BUFFER_SIZE);
        try {
            writer = new BufferedWriter(new OutputStreamWriter(out, Constants.UTF8));
        } catch (UnsupportedEncodingException e) {
            throw DbException.convert(e);
        }
    }
View Full Code Here

Examples of java.io.BufferedWriter

     * whatever the encoding
     * @throws IOException on error
     */   
    public static void exportToXML(List list, OutputStream out, String encoding, boolean onlyASCII) throws IOException {
        String jenc = IanaEncodings.getJavaEncoding(encoding);
        Writer wrt = new BufferedWriter(new OutputStreamWriter(out, jenc));
        exportToXML(list, wrt, encoding, onlyASCII);
    }
View Full Code Here

Examples of java.io.BufferedWriter

      flush();
  }

  public void flush() {
    if (fileOutput && buffer.size() > 0) {
      BufferedWriter bufferedWriter = null;
      try {
        bufferedWriter = getBufferedWriter();
        for (LogItem logItem = null; (logItem = buffer.poll()) != null;) {
          bufferedWriter.append(logItem.toString() + CL);
        }
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        if (bufferedWriter != null)
          try {
            bufferedWriter.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
      }
    }
View Full Code Here

Examples of java.io.BufferedWriter

      ret = file.createNewFile();
    } else {
      ret = true;
    }
    if (ret)
      return new BufferedWriter(new FileWriter(file, true));
    else
      return null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.