Search in sources :

Example 66 with Format

use of java.text.Format in project j2objc by google.

the class TCKDateTimeFormatter method test_toFormat_format.

// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
@Test
public void test_toFormat_format() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 67 with Format

use of java.text.Format in project j2objc by google.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_nullParsePosition.

@Test(expected = NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullParsePosition() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.parseObject("ONE30", (ParsePosition) null);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 68 with Format

use of java.text.Format in project j2objc by google.

the class TCKDateTimeFormatter method test_toFormat_Query_format.

// -----------------------------------------------------------------------
@Test
public void test_toFormat_Query_format() throws Exception {
    Format format = BASIC_FORMATTER.toFormat();
    String result = format.format(LocalDate.of(2008, 6, 30));
    assertEquals(result, "ONE30");
}
Also used : Format(java.text.Format) Test(org.junit.Test)

Example 69 with Format

use of java.text.Format in project j2objc by google.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_parseError.

@Test
public void test_toFormat_parseObject_StringParsePosition_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
    // TODO: is this right?
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
Also used : Format(java.text.Format) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Example 70 with Format

use of java.text.Format in project SAGU by brianmcmichael.

the class InventoryRequest method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jbtInventoryRequest) {
        SwingWorker<Object, Void> inventoryWorker = new SwingWorker<Object, Void>() {

            @Override
            protected Object doInBackground() throws Exception {
                // Create dumb progressbar
                Date d = new Date();
                JFrame inventoryFrame = new JFrame("Waiting for inventory");
                {
                    inventoryFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(d);
                    cal.add(Calendar.MINUTE, 250);
                    String doneString = cal.getTime().toString();
                    JLabel doneTimeLabel = new JLabel("<html><body>Inventory of vault " + irVault + " requested.<br>Estimated completion by " + doneString + "</html></body>");
                    final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
                    dumJProgressBar.setIndeterminate(true);
                    inventoryFrame.add(dumJProgressBar, BorderLayout.NORTH);
                    inventoryFrame.add(doneTimeLabel, BorderLayout.CENTER);
                    inventoryFrame.setBackground(wc);
                    inventoryFrame.setSize(300, 60);
                }
                centerDefineFrame(inventoryFrame, 500, 100);
                inventoryFrame.setVisible(true);
                try {
                    JobParameters jParameters = new JobParameters().withType("inventory-retrieval");
                    InitiateJobRequest initJobRequest = new InitiateJobRequest().withVaultName(irVault).withJobParameters(jParameters);
                    InitiateJobResult initJobResult = irClient.initiateJob(initJobRequest);
                    String thisJobId = initJobResult.getJobId();
                    Thread.sleep(12600000);
                    Boolean success = waitForJob(irClient, irVault, thisJobId);
                    while (!success) {
                        Thread.sleep(WAIT_TIME);
                        success = waitForJob(irClient, irVault, thisJobId);
                    }
                    GetJobOutputRequest gjoRequest = new GetJobOutputRequest().withVaultName(irVault).withJobId(thisJobId);
                    GetJobOutputResult gjoResult = irClient.getJobOutput(gjoRequest);
                    Format formatter = new SimpleDateFormat("yyyyMMMdd_HHmmss");
                    String fileDate = formatter.format(d);
                    String fileName = irVault + fileDate + ".txt";
                    String filePath = "" + CUR_DIR + System.getProperty("file.separator") + fileName;
                    FileWriter fileStream = new FileWriter(filePath);
                    BufferedWriter out = new BufferedWriter(fileStream);
                    BufferedReader in = new BufferedReader(new InputStreamReader(gjoResult.getBody()));
                    String inputLine;
                    while ((inputLine = in.readLine()) != null) {
                        out.write(inputLine);
                    }
                    out.close();
                    inventoryFrame.setVisible(false);
                    JOptionPane.showMessageDialog(null, "Successfully exported " + irVault + " inventory to " + filePath.toString(), "Saved", JOptionPane.INFORMATION_MESSAGE);
                    return null;
                } catch (AmazonServiceException k) {
                    JOptionPane.showMessageDialog(null, "The server returned an error. Files will not be inventoried for 24 hours after upload. Also check that correct location of vault has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE);
                    System.out.println("" + k);
                    inventoryFrame.setVisible(false);
                } catch (AmazonClientException i) {
                    JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Inventory not requested.", "Error", JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                } catch (Exception j) {
                    JOptionPane.showMessageDialog(null, "Inventory not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE);
                    inventoryFrame.setVisible(false);
                }
                return null;
            }
        };
        inventoryWorker.execute();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        this.setVisible(false);
        dispose();
    } else if (e.getSource() == jbtBack) {
        this.setVisible(false);
        dispose();
    } else {
        JOptionPane.showMessageDialog(this, "Please choose a valid action.");
    }
}
Also used : FileWriter(java.io.FileWriter) AmazonClientException(com.amazonaws.AmazonClientException) BufferedWriter(java.io.BufferedWriter) Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) InputStreamReader(java.io.InputStreamReader) Calendar(java.util.Calendar) Date(java.util.Date) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) BufferedReader(java.io.BufferedReader) AmazonServiceException(com.amazonaws.AmazonServiceException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Format (java.text.Format)160 SimpleDateFormat (java.text.SimpleDateFormat)63 DecimalFormat (java.text.DecimalFormat)39 Test (org.junit.Test)38 DateFormat (java.text.DateFormat)34 Date (java.util.Date)32 NumberFormat (java.text.NumberFormat)29 DateTimeFormatter (java.time.format.DateTimeFormatter)27 ChoiceFormat (java.text.ChoiceFormat)24 ParsePosition (java.text.ParsePosition)22 MessageFormat (java.text.MessageFormat)20 FieldPosition (java.text.FieldPosition)16 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)15 ParseException (java.text.ParseException)11 ArrayList (java.util.ArrayList)11 Locale (java.util.Locale)10 AttributedString (java.text.AttributedString)9 TemporalAccessor (java.time.temporal.TemporalAccessor)7 Calendar (java.util.Calendar)7