/** * Creates a GPX-formatted file attachment for the given entry. * * @param user * @param entryId * @param fileName * @param activityId * @param track * @param track */ public void createAttachment( User user, int entryId, String fileName, String title, String activityId, GpsTrack track) throws DataAccessException, IOException { Attachment a = new Attachment(); a.setUserName(user.getUserName()); a.setUserId(user.getUserId()); a.setEntryId(entryId); a.setFileType("map"); a.setFileName(fileName); a.setActivityId(activityId); a.setTitle(title); GpxFormatter formatter = new GpxFormatter(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); List<GpsTrack> tracks = new ArrayList<GpsTrack>(); tracks.add(track); formatter.format(tracks, baos); log.debug(new String(baos.toByteArray())); a.setBytes(baos.toByteArray()); new AttachmentDao().create(a); }